두 벡터 t
및 delta
- 길이가 모두 n
입니다. 그 벡터와 함께 희미한 DIA
행렬 A
을 만들고 난 다음 열을 조정하고 싶습니다. 모두 i
의 경우 A
에 ith
항목을 왼쪽으로 delta[i]
열로 이동하고 싶습니다.희소 DIA 행렬을 만든 다음 열을 변경하십시오.
열을 쉽게 제어하는 방법은 COO
형식입니다. 여기에 내가 일 것이라고 생각 무엇 : t
및 delta
의 길이가 239
동안
from scipy.sparse import diags
A = diags([t], offsets=[-1]).tocoo()
A.col = A.col - delta
하지만, 내 예제에서 A.nnz == len(A.col)
는 만 216
이다. 나는 그 일이 어떻게되었는지 이해하지 못한다. nnz
은 "Number of stored values, including explicit zeros."이다.
이 문제를 어떻게 해결할 수 있습니까? 0 밖으로
from numpy import np
t = np.array([ 2.655, 2.655, 2.655, 2.655, 2.655, 2.655, 2.655, 2.655,
2.655, 2.655, 2.655, 2.655, 2.655, 2.655, 2.655, 2.655,
2.655, 2.655, 2.655, 2.655, 2.655, 2.655, 2.655, 2.155,
2.155, 2.155, 2.155, 2.155, 2.155, 2.155, 2.155, 2.155,
2.155, 2.155, 2.155, 2.155, 2.155, 2.155, 2.155, 2.155,
2.155, 2.155, 2.155, 2.155, 2.155, 2.155, 2.155, 1.655,
1.655, 1.655, 1.655, 1.655, 1.655, 1.655, 1.655, 1.655,
1.655, 1.655, 1.655, 1.655, 1.655, 1.655, 1.655, 1.655,
1.655, 1.655, 1.655, 1.655, 1.655, 1.655, 1.655, 1.155,
1.155, 1.155, 1.155, 1.155, 1.155, 1.155, 1.155, 1.155,
1.155, 1.155, 1.155, 1.155, 1.155, 1.155, 1.155, 1.155,
1.155, 1.155, 1.155, 1.155, 1.155, 1.155, 1.155, 0.655,
0.655, 0.655, 0.655, 0.655, 0.655, 0.655, 0.655, 0.655,
0.655, 0.655, 0.655, 0.655, 0.655, 0.655, 0.655, 0.655,
0.655, 0.655, 0.655, 0.655, 0.655, 0.655, 0.655, 0.405,
0.405, 0.405, 0.405, 0.405, 0.405, 0.405, 0.405, 0.405,
0.405, 0.405, 0.405, 0.405, 0.405, 0.405, 0.405, 0.405,
0.405, 0.405, 0.405, 0.405, 0.405, 0.405, 0.405, 0.405,
0.405, 0.405, 0.405, 0.405, 0.405, 0.405, 0.405, 0.405,
0.405, 0.405, 0.405, 0.405, 0.405, 0.405, 0.405, 0.405,
0.405, 0.405, 0.405, 0.405, 0.405, 0.405, 0.405, 0.405,
0.405, 0.405, 0.405, 0.405, 0.405, 0.405, 0.405, 0.405,
0.405, 0.405, 0.405, 0.405, 0.405, 0.405, 0.405, 0.405,
0.405, 0.405, 0.405, 0.405, 0.405, 0.405, 0.405, 0.405,
0.405, 0.405, 0.405, 0.405, 0.405, 0.405, 0.405, 0.405,
0.405, 0.405, 0.405, 0.405, 0.405, 0.405, 0.405, 0.405,
0.405, 0.405, 0.405, 0.405, 0.405, 0.405, 0.405, 0. ,
0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. , 0. , 0. ])
delta = np.array([0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5,
5, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5,
5, 5, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5,
5, 5, 5, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4,
5, 5, 5, 5, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4,
4, 5, 5, 5, 5, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4,
4, 4, 5, 5, 5, 5, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4,
4, 4, 4, 5, 5, 5, 5, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3,
4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3,
3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0, 0, 1, 1, 1, 1, 2, 0, 2, 2, 3, 2,
1, 3, 4, 3, 0, 3, 5, 4, 1, 0])