Skip to content
Advertisement

Multidimensional arrays, using range, while simultaneously having a set start, stop, and step?

Oy mates,

I am learning numpy on my own and getting a pretty good handle on it, a few concepts elude me even after reading the documentation though. I am trying to go through this matrix and make every second row have 10s all the way through it.

JavaScript

The last line of code is incorrect. I know how to use slicing by using semi colons – list[start:stop:step] and I know how to use fancy indexing to go through matrices by using commas ndarray[range(end1),range(end2)] but how do I combine these two methods?

How do I step through a multidimensional array, using range, while simultaneously having a set start, stop, and step?

Advertisement

Answer

I think what you want is this:

JavaScript

The issue is here:

JavaScript

You need to apply the slice syntax to the range explicitly:

JavaScript

For general reference you can do:

JavaScript

Where the first np.arange chooses the rows and the second np.aranage chooses the columns.

A few references that may help:

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement