HighwayJohn HighwayJohn - 2 years ago 144
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.

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download