Skip to main content

12.12) More Dimensions (cont'd)


Here’s how a 3D arrays gets filled:

>>> B[1,2,3]=99.9
>>> B[1,0,1]=55.5
>>> B[0,:,3]=44.4
>>> print B
[[[  1.    1.    1.   44.4]
  [  1.    1.    1.   44.4]
  [  1.    1.    1.   44.4]]
 [[  1.   55.5   1.    1. ]
  [  1.    1.    1.    1. ]
  [  1.    1.    1.   99.9]]]

We’ve showed here that NumPy arrays are mutable object. Remember also that referencing an array with a new name does not copy an array. To make a copy use the [:] notation like you do with lists:

>>> A=B   # A and B now reverence the same array
>>> C=B[:]  # C is a copy of B