pombreda / winpython

Automatically exported from code.google.com/p/winpython
0 stars 0 forks source link

Numpy Slicing Problem #85

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. import numpy as np
2. dim2_array = np.array( [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]] )
3. print( dim2_array[1:2, 2:3] )

What is the expected output? What do you see instead?
Expected:  
[[7 8]
 [11 12]]
What I get:
[[7]]

It seems that for array slicing, this version treats the first number as base 
0, 1, 2, etc for arrays, but the second as base 1, 2, 3, etc.

print( dim2_array[1:3, 2:4] ) gets the desired output, but this doesn't make 
much sense to me.

What version of the product are you using? On what operating system?
WinPython-64bit-3.3.2.3 on Windows 8

Please provide any additional information below.

Original issue reported on code.google.com by sroec...@gmail.com on 24 Sep 2013 at 5:11

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Actually, I think everything is working exactly as Python is designed.  In 
NumPy array slices, like Python list slices, the second parameter in a:b:c can 
be thought of as "up to but not including b."  About halfway down this page
http://docs.python.org/2/tutorial/introduction.html#strings

there is an illustration I'll copy here...
"""
One way to remember how slices work is to think of the indices as pointing 
between characters, with the left edge of the first character numbered 0. Then 
the right edge of the last character of a string of n characters has index n, 
for example:
 +---+---+---+---+---+
 | H | e | l | p | A |
 +---+---+---+---+---+
 0   1   2   3   4   5
"""

You might want to spend some time on that Python doc page above, or at the 
following.
http://scipy-lectures.github.io/intro/numpy/array_object.html#indexing-and-slici
ng

Probably should be marked as non-issue.

Original comment by j...@passmore4.com on 18 Nov 2013 at 5:00