今天又解决了一个之前一直困惑的问题,就是在程序中通常会看到这样的代码a[…,0],或者a[…,0:-1]
import numpy as np
import tensorflow as tf
a=np.array([[[1,2,3],[4,5,6]],[[7,8,9],[0,1,2]],[[3,4,5],[6,7,8]]])
print(a)
print(a.shape)
a的输出
[[[1 2 3]
[4 5 6]]
[[7 8 9]
[0 1 2]]
[[3 4 5]
[6 7 8]]]
(3, 2, 3)
示意图
将其分解就是由3个两行三列的数组构成的。(j)
b=a[...,0]
print(b)
print(b.shape)
b1=a[0,0]
print(b1)
print(b1.shape)
…代表取满空间上的每一片
b
[[1 4]
[7 0]
[3 6]]
(3, 2)
b1
[1 2 3]
(3,)
c=a[...,0:1]
print(c)
print(c.shape)
c1=a[...,0:3]
print(c1)
print(c1.shape)
c2=a[0,0,0]
print(c2)
print(c2.shape)
c:
[[[1]
[4]]
[[7]
[0]]
[[3]
[6]]]
(3, 2, 1)
c1
[[[1 2 3]
[4 5 6]]
[[7 8 9]
[0 1 2]]
[[3 4 5]
[6 7 8]]]
(3, 2, 3)
c2
1
()