numpy 中np.array 與 np.ndarry的區別

weixin_41874599發表於2018-11-07
import numpy as np
result = np.ndarray([0, 4])
print(result)
print(len(result))
a = np.array([1,2,3])
c=np.ndarray([1,2,3])
print (a)
print(c)
print(c[0])
print(c.shape)
print(result.shape)

[]
0
[1 2 3]
[[[6.91616094e-310 6.91616094e-310 6.91616094e-310]
  [6.91616094e-310 6.91616094e-310 6.91616094e-310]]]
[[6.91616094e-310 6.91616094e-310 6.91616094e-310]
 [6.91616094e-310 6.91616094e-310 6.91616094e-310]]
(1, 2, 3)
(0, 4)

Process finished with exit code 0

由上圖程式可以看出,ndarray是建立對應維度的陣列的形狀容器,array是將()內的轉換為陣列

 

相關文章