-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestii.py
46 lines (36 loc) · 998 Bytes
/
testii.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import numpy as np
import operator
import scipy.sparse as sp
NumerovMatrix1D = []
XDIV = 4
V = np.array([.5,1,1.5,2])
Nele = 0
print xrange(XDIV)
for i in xrange(XDIV):
print (i)
for i in xrange(XDIV):
NumerovMatrix1D.append([1+i, 1+i, V[i], 10.0])
#print(NumerovMatrix1D)
Nele += 1
if i-1 >=0:
NumerovMatrix1D.append([1+i, 0, V[i-1], 1])
Nele += 1
#print(NumerovMatrix1D)
if i+1 <XDIV:
NumerovMatrix1D.append([1+i, 2+i, V[i+1], 1])
Nele +=1
#print(NumerovMatrix1D)
NumerovMatrix1D = sorted(NumerovMatrix1D, key=operator.itemgetter(0,1))
print(NumerovMatrix1D)
NumerovMatrix1D = np.array(NumerovMatrix1D)
print(NumerovMatrix1D)
row = NumerovMatrix1D[:, 0] - 1
print(row)
col = NumerovMatrix1D[:, 1] - 1
print(col)
dataM = NumerovMatrix1D[:,2]
print(dataM)
dataA = NumerovMatrix1D[:,3]
print(dataA)
A = sp.coo_matrix((dataA, (row, col)), shape=(XDIV, XDIV))
M = sp.csr_matrix((dataM, (row, col)), shape=(XDIV, XDIV))