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)?

Asked By: Bruce

||

Answers:

Here’s how:

a[i,j] = x
Answered By: Can Berk Güder

Try this

a[i,j]=5
Answered By: John La Rooy

Or

a.itemset((i,j),x)
Answered By: YOU
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.