I want to set the last 7 columns in the given matrix. Here is the code I used

temp = mat('[6 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 2 0 0 0 4; 0 3 0 0 0 0 0 3 0 0]')
m,n = temp.shape

for i in range(3,n):
            temp[0][i] = 0.0
print temp

It gives an error "index out of bounds". Can anybody point what's wrong?

Recommended Answers

All 3 Replies

Gentle Bounce. :)
P.S. I am using the numpy module. So basically the problem I am having is how to iterate over instances provided by numpy l(ike matrix)

Gentle Bounce :)
P.S I am using the numpy module. And the problem I am having is how to iterate over the instances returned by numpy like a matrix in this case.

In NumPy, you don't use the standard list indexes. Instead, you need to pass it a list with the appropriate index values:

for i in range(3, n):
    temp[0, i] = 0.0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.