Python: Setting an element of a Numpy matrix
Question:
I am a pretty new to python. I have created an empty matrix
a = numpy.zeros(shape=(n,n))
Now I can access each element using
a.item(i,j)
How do I set an index (i,j)?
Answers:
Here’s how:
a[i,j] = x
Try this
a[i,j]=5
Or
a.itemset((i,j),x)
I am a pretty new to python. I have created an empty matrix
a = numpy.zeros(shape=(n,n))
Now I can access each element using
a.item(i,j)
How do I set an index (i,j)?
Here’s how:
a[i,j] = x
Try this
a[i,j]=5
Or
a.itemset((i,j),x)