HighwayJohn HighwayJohn - 7 months ago 25
Python Question

Last element of an multidimensional matrix

I have a multidimensional matrix and want to set the last element to 1.(e.g.

w[1,1,1,1,1]= 1)
The dimension varies, so thats my problem.
po[-1]=1
doesn't work here.

Answer

I'm going to assume you're using NumPy since Python itself doesn't have multidimensional arrays.

The easy way to do this is using a "flat" view of the array:

myarray.flat[-1] = 1