Basic NumPy array replacement
08:30 04 May 2016

I have a rather basic question about the NumPy module in Python 2, particularly the version on trinket.io. I do not see how to replace values in a multidimensional array several layers in, regardless of the method. Here is an example:

a = numpy.array([1,2,3])
a[0] = 0

print a

a = numpy.array([[1,2,3],[1,2,3]])
a[0][0] = a[1][0] = 0

print a

Result:

array([0, 2, 3], '')
array([[1, 2, 3], [1, 2, 3]], '')

I need the ability to change individual values, my specific code being:

a = numpy.empty(shape = (8,8,2),dtype = str)

for row in range(a.shape[0]):
  for column in range(a.shape[1]):
    a[row][column][1] = 'a'

Thank you for your time and any help provided.

python arrays numpy trinket.io