Python Forum
2 Dimensional NumPy for beginners
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
2 Dimensional NumPy for beginners
#3
Try to put your code in [python][/python] markers or the indent is lost...

The answer is correct, you need to take into account 2 important aspects of python (and numpy):
- The indexes start to count at 0
- The ranges never reach the latest value, so 1:4 is 1, 2, and 3

So when you say ridership[1:3, 3:5] you are asking for the elements from row 1 to 3 excluded (so 2nd and 3rd rows) and columns from 3 to 5 excluded (so columns 4th and 5th)

If this feels strange, it is really powerful... the reason to not to include the upper bound of a slice is obvious when you notice that in that way is:
a[0:3] + a[3:10] == a[0:10]
And that helps a lot to avoid missing or repeating elements wen playing with lists or matrices.
Reply


Messages In This Thread
2 Dimensional NumPy for beginners - by Jack_Sparrow - May-08-2018, 05:01 PM
RE: 2 Dimensional NumPy for beginners - by killerrex - May-08-2018, 05:21 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Numpy] How to store different data type in one numpy array? water 7 619 Mar-26-2024, 02:18 PM
Last Post: snippsat
  Numpy returns "TypeError: unsupported operand type(s) for *: 'numpy.ufunc' and 'int'" kalle 2 2,636 Jul-19-2022, 06:31 AM
Last Post: paul18fr
  PyTorch for beginners OmegaRed94 1 1,105 Jun-09-2022, 09:20 PM
Last Post: Larz60+
  "erlarge" a numpy-matrix to numpy-array PhysChem 2 3,004 Apr-09-2019, 04:54 PM
Last Post: PhysChem
  How to add an element such as an average to a multi-dimensional array? xhughesey 6 4,010 Jan-06-2019, 10:47 PM
Last Post: xhughesey
  Three-dimensional Contour Plots minifizikus 1 3,277 Sep-13-2018, 10:56 PM
Last Post: Larz60+
  Recurse through n-dimensional array ColdDeath 2 2,987 Apr-05-2018, 11:20 AM
Last Post: KenniT
  Two Dimensional Chart from CSV File srini1995 0 2,236 Nov-27-2017, 07:10 AM
Last Post: srini1995
  How to sum elements of same position in n dimensional array Felipe 2 4,135 May-11-2017, 10:33 AM
Last Post: Felipe

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020