import numpy as np
print(np.rint(1.5))
print(2**3)
a=[[1,2,3,4,5],
[2,3,4,5,6]]
print(type(a))
a=np.array(a)
print(type(a))
print(a)
print(a.shape)
summed=np.sum(a,axis=0)
print(summed)
summed2=np.sum(a,axis=1)
print(summed2)
b=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]
b=np.array(b)
b=b.reshape(2,4,3)
print(b.shape)
print(b.size)
print(b)
print(b.shape[0])
summed=np.sum(b,axis=0)
print(summed)
print(summed.shape)
summed2=np.sum(b,axis=1)
print(summed2)
print(summed2.shape)
summed3=np.sum(b,axis=2)
print(summed3)
print(summed3.shape)
#X的shape(x,y,z),即X.shape=(x,y,z),X.shape[0]是x x是最外层 axis0是最外层相加 加完变成(y,z)
2.0
8
<class ‘list’>
<class ‘numpy.ndarray’>
[[1 2 3 4 5]
[2 3 4 5 6]]
(2, 5)
[ 3 5 7 9 11]
[15 20]
(2, 4, 3)
24
[[[ 1 2 3]
[ 4 5 6]
[ 7 8 9]
[10 11 12]]
[[13 14 15]
[16 17 18]
[19 20 21]
[22 23 24]]]
2
[[14 16 18]
[20 22 24]
[26 28 30]
[32 34 36]]
(4, 3)
[[22 26 30]
[70 74 78]]
(2, 3)
[[ 6 15 24 33]
[42 51 60 69]]
(2, 4)
Process finished with exit code 0