HighwayJohn HighwayJohn - 1 year ago 78
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.
doesn't work here.


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