#1 从已存在的数据创建numpy数组
a = [[1,2,3],[4,5,6],[7,8,9],[10,11,12]]
b = np.array(a)
Out[21]:
array([[ 1, 2, 3],
[ 4, 5, 6],
[ 7, 8, 9],
[10, 11, 12]])
#2
ima = [[0,1,2,3],[0,0,0,0],[2,2,2,2]]
ima = np.array(ima)
ima.astype(int) #可以将ima的数据类型重定义
Out[13]:
array([[0, 1, 2, 3],
[0, 0, 0, 0],
[2, 2, 2, 2]])
#3 numpy数组,内数组寻址(这个标题起不好)
b[ima.astype(int)]
Out[17]:
array
[[[ 1, 2, 3],
[ 4, 5, 6],
[ 7, 8, 9],
[ 10, 11, 12]],
[[ 1, 2, 3],
[ 1, 2, 3],
[ 1, 2, 3],
[ 1, 2, 3]],
[[ 7, 8, 9],
[ 7, 8, 9],
[ 7, 8, 9],
[ 7, 8, 9]]])