修订版 | 6612252ca3b5cc2900a43872987f35bd8ffc9d21 (tree) |
---|---|
时间 | 2024-06-26 04:53:05 |
作者 | Lorenzo Isella <lorenzo.isella@gmai...> |
Commiter | Lorenzo Isella |
I simple python script showcasing new.axis to quickly define a matrix in Python.
@@ -0,0 +1,21 @@ | ||
1 | +import numpy as np | |
2 | + | |
3 | +#Now it is time to evaluate the matrix N_mat[i,j]=n[i]n[j] | |
4 | + | |
5 | +n= np.arange(4) | |
6 | + | |
7 | +n | |
8 | + | |
9 | +m=np.arange(6) | |
10 | + | |
11 | +m | |
12 | + | |
13 | +## Now I will define the matrix N_mat[i,j]=m[i]*n[j] with 6 rows | |
14 | +## and 4 columns | |
15 | + | |
16 | +N_mat=m[:,np.newaxis]*n[np.newaxis,:] | |
17 | + | |
18 | +N_mat | |
19 | + | |
20 | +## which is very close to the mathematical definition. Can I achieve something | |
21 | +## similar in R? |