sparse-matrix

Matlab uint8 sparse

青春壹個敷衍的年華 提交于 2019-12-01 09:23:59
问题 When creating a sparse matrix in Matlab it seems that you can create a sparse matrix either filled with logicals or double valued numbers. While reading around I understood that Matlab does not have support for other type of sparse matrices, i.e. uint8 or other integers. In my application I know that max(values)==16 , and the memory is a crucial thing, therefore I would like to have uint8 sparse matrices. Is there a way of creating a unit8 sparse matrix? If not (most likely), is there any

Merge two dgCMatrix sparse matrices of different size in R

别说谁变了你拦得住时间么 提交于 2019-12-01 07:32:41
问题 How can I merge two large (around 500k columns and rows) sparse matrices of formal class dgCMatrix with different sizes (both columns and rows wise) in R? Simplyfied example: I have a full 6x6 matrix 1 2 3 4 5 6 1 0 0 0 0 0 0 2 0 0 0 0 0 0 3 0 0 0 0 0 0 4 0 0 0 0 0 0 5 0 0 0 0 0 0 6 0 0 0 0 0 0 Now I want to merge a second matrix of different size: 3 4 5 6 1 0 1 0 0 3 0 0 1 0 4 1 0 0 0 The result should be: 1 2 3 4 5 6 1 0 0 0 1 0 0 2 0 0 0 0 0 0 3 0 0 0 0 1 0 4 1 0 0 0 0 0 5 0 0 0 0 0 0 6 0

Multiplying elements in a sparse array with rows in matrix

拜拜、爱过 提交于 2019-12-01 05:22:26
If you have a sparse matrix X: >> X = csr_matrix([[0,2,0,2],[0,2,0,1]]) >> print type(X) >> print X.todense() <class 'scipy.sparse.csr.csr_matrix'> [[0 2 0 2] [0 2 0 1]] And a matrix Y: >> print type(Y) >> print text_scores <class 'numpy.matrixlib.defmatrix.matrix'> [[8] [5]] ...How can you multiply each element of X by the rows of Y. For example: [[0*8 2*8 0*8 2*8] [0*5 2*5 0*5 1*5]] or: [[0 16 0 16] [0 10 0 5]] I've tired this but obviously it doesn't work as the dimensions dont match: Z = X.data * Y Unfortunatly the .multiply method of the CSR matrix seems to densify the matrix if the other

Adding a column of zeroes to a csr_matrix

杀马特。学长 韩版系。学妹 提交于 2019-12-01 04:26:05
I have an MxN sparse csr_matrix , and I'd like to add a few columns with only zeroes to the right of the matrix. In principle, the arrays indptr , indices and data keep the same, so I only want to change the dimensions of the matrix. However, this seems to be not implemented. >>> A = csr_matrix(np.identity(5), dtype = int) >>> A.toarray() array([[1, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 1]]) >>> A.shape (5, 5) >>> A.shape = ((5,7)) NotImplementedError: Reshaping not implemented for csr_matrix. Also horizontally stacking a zero matrix does not seem to work

Matlab 3d-matrix

╄→гoц情女王★ 提交于 2019-12-01 04:17:31
I have to create a very big 3D matrix (such as: 500000x60x60 ). Is there any way to do this in matlab? When I try omega = zeros(500000,60,60,'single'); I get an out-of-memory error. The sparse function is no option since it is only meant for 2D matrices. So is there any alternative to that for higher dimensional matrices? Matlab only has support for sparse matrices (2D). For 3D tensors/arrays, you'll have to use a workaround. I can think of two: linear indexing cell arrays Linear indexing You can create a sparse vector like so: A = spalloc(500000*60*60, 1, 100); where the last entry ( 100 )

Element-wise power of scipy.sparse matrix

五迷三道 提交于 2019-12-01 02:31:08
How do I raise a scipy.sparse matrix to a power, element-wise? numpy.power should, according to its manual , do this, but it fails on sparse matrices: >>> X <1353x32100 sparse matrix of type '<type 'numpy.float64'>' with 144875 stored elements in Compressed Sparse Row format> >>> np.power(X, 2) Traceback (most recent call last): File "<stdin>", line 1, in <module> File ".../scipy/sparse/base.py", line 347, in __pow__ raise TypeError('matrix is not square') TypeError: matrix is not square Same problem with X**2 . Converting to a dense array works, but wastes precious seconds. I've had the same

Adding a column of zeroes to a csr_matrix

谁都会走 提交于 2019-12-01 02:28:46
问题 I have an MxN sparse csr_matrix , and I'd like to add a few columns with only zeroes to the right of the matrix. In principle, the arrays indptr , indices and data keep the same, so I only want to change the dimensions of the matrix. However, this seems to be not implemented. >>> A = csr_matrix(np.identity(5), dtype = int) >>> A.toarray() array([[1, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 1]]) >>> A.shape (5, 5) >>> A.shape = ((5,7)) NotImplementedError:

Multiplying elements in a sparse array with rows in matrix

感情迁移 提交于 2019-12-01 02:09:31
问题 If you have a sparse matrix X: >> X = csr_matrix([[0,2,0,2],[0,2,0,1]]) >> print type(X) >> print X.todense() <class 'scipy.sparse.csr.csr_matrix'> [[0 2 0 2] [0 2 0 1]] And a matrix Y: >> print type(Y) >> print text_scores <class 'numpy.matrixlib.defmatrix.matrix'> [[8] [5]] ...How can you multiply each element of X by the rows of Y. For example: [[0*8 2*8 0*8 2*8] [0*5 2*5 0*5 1*5]] or: [[0 16 0 16] [0 10 0 5]] I've tired this but obviously it doesn't work as the dimensions dont match: Z =

Matlab: fast way to sum ones in binary numbers with Sparse structure?

房东的猫 提交于 2019-12-01 01:56:23
Most answers only address the already-answered question about Hamming weights but ignore the point about find and dealing with the sparsity. Apparently the answer by Shai here addresses the point about find -- but I am not yet able to verify it. My answer here does not utilise the ingenuity of other answers such as the bitshifting but good enough example answer. Input >> mlf=sparse([],[],[],2^31+1,1);mlf(1)=10;mlf(10)=111;mlf(77)=1010; >> transpose(dec2bin(find(mlf))) ans = 001 000 000 011 001 010 101 Goal 1 0 0 2 1 1 2 Fast calculation for the amount of ones in binary numbers with the sparse

How Tensorflow handles categorical features with multiple inputs within one column?

半世苍凉 提交于 2019-12-01 01:03:45
For example, I have a data in the following csv format: csv col0 col1 col2 col3 1 A E|A|C 3 0 B D|F 2 2 C | 2 Each column seperated by comma represent one feature. Normally, a feature is one-hot(e.g. col0, col1, col3 ), but in this case, the feature for col2 has multiple inputs(seperated by |). I'm sure tensorflow can handle one-hot feature with sparse tensor, but I'm not sure whether it could handle features with multiple inputs like col2 ? How should it be represented in Tensorflow's sparse tensor? I am using the code below (but i don't know input method of col2 ) col0 = tf.feature_column