Is It Possible To Cast Dtype Of Scipy Csr Matrix To Npy_float?
I have a scipy CSR matrix that was constructed from a COO matrix as follows: coord_mat = coo_matrix((data, (row, col)), dtype=np.float64) It is being used as an input to a library
Solution 1:
I'm not sure about the C
interface, I'll try to explain the coo_matrix
part.
Since you are using the tuple input it splits that into 3 variables
obj, (row, col) = arg1
then it assigns those to attributes
self.row = np.array(row, copy=copy, dtype=idx_dtype)
self.col = np.array(col, copy=copy, dtype=idx_dtype)
self.data = np.array(obj, copy=copy)
and since you specified a dtype
if dtype isnotNone:
self.data = self.data.astype(dtype)
If data
, row
and col
are already arrays, any you didn't specify the dtype, the sparse matrix can use those inputs as attributes without copying. Your dtype parameter will produce a copy.
The sparse matrix is not a numpy
array, but rather an object that has 3 arrays as attribute. The matrix accepts the astype
method, which probably does that same self.data.astype
action. So I think you case comes down to: can you cast any array to that type.
Post a Comment for "Is It Possible To Cast Dtype Of Scipy Csr Matrix To Npy_float?"