The [:, :]
stands for everything from the beginning to the end just like for lists. The difference is that the first :
stands for first and the second :
for the second dimension.
a = numpy.zeros((3, 3))
In [132]: a
Out[132]:
array([[ 0., 0., 0.],
[ 0., 0., 0.],
[ 0., 0., 0.]])
Assigning to second row:
In [133]: a[1, :] = 3
In [134]: a
Out[134]:
array([[ 0., 0., 0.],
[ 3., 3., 3.],
[ 0., 0., 0.]])
Assigning to second column:
In [135]: a[:, 1] = 4
In [136]: a
Out[136]:
array([[ 0., 4., 0.],
[ 3., 4., 3.],
[ 0., 4., 0.]])
Assigning to all:
In [137]: a[:] = 10
In [138]: a
Out[138]:
array([[ 10., 10., 10.],
[ 10., 10., 10.],
[ 10., 10., 10.]])
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…