모양이 매우 거대한 희소 행렬을 만들려고합니다. (447957347, 5027974)
. 그리고 3,289,288,566 개의 요소가 포함되어 있습니다. 내가 변환 할 때 나는 또한 발견,scipy에서 거대한 희소 행렬을 만드는 법
indptr = np.array(a, dtype=np.uint32) # a is a python array('L') contain row index information
indices = np.array(b, dtype=np.uint32) # b is a python array('L') contain column index information
data = np.ones((len(indices),), dtype=np.uint32)
test = csr_matrix((data,indices,indptr), shape=(len(indptr)-1, 5027974), dtype=np.uint32)
그리고 :
<447957346x5027974 sparse matrix of type '<type 'numpy.uint32'>'
with -1005678730 stored elements in Compressed Sparse Row format>
매트릭스를 만들기위한 소스 코드는 다음과 같습니다 나는 csr_matrix
가 scipy.sparse
를 사용하여 만들 때, 그것은 이런 식으로 뭔가를 반환
하지만, 30 억 길이의 python 배열이 numpy 배열이면 오류가 발생합니다.
ValueError:setting an array element with a sequence
그러나 10 억 개의 파이썬 배열을 10 억 개 만들어 numpy 배열로 변환 한 다음 추가합니다. 그것은 잘 작동합니다.
나는 혼란 스럽다.
'a'와'b'를 기술하는 대신 예제 데이터를 생성하는 코드를 추가 할 수 있습니까? – YXD
@Ofey 아마도 당신은 현재 접근법보다 쉬운 희소 행렬을 만들기 위해 coo_matrix를 사용할 수 있습니다 :'test = coo_matrix ((data, (rows, cols)), shape = (m, n))' –
32 비트 파이썬 또는 32 비트 시스템 사용? 32 비트 부호있는 정수 제한을 치는 것 같습니다. – jrennie