I have a multidimensional matrix and want to set the last element to 1.(e.g.
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