注意区分如下几种用法,
- 使用type()获取数据类型;
- 主要是分清数组的shape,每一维都是什么;
- 只有是具体到一维时,才能用len();
- 注意np.array(),小括号中是否有中括号,是否又增加了一维。
import numpy as np
a = [1, 2, 3, 4]
b = np.array(a)
print(b, type(b), b.shape, len(b), b[0])
c = np.array([b])
print(c, type(c), c.shape, c[0], len(c[0]), c[0][0])
d = np.array([[1],[2],[3],[4]])
print(d, type(d), d.shape, d[0], len(d[0]), d[0][0])