Python Forum
regarding the usage of crop_data = data[:,offset1:-offset1, offset2:-offset2]
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
regarding the usage of crop_data = data[:,offset1:-offset1, offset2:-offset2]
#1
While reading an existing software, I once read the following code segment

crop_data = data[:,offset1:-offset1, offset2:-offset2]
I think crop_data will be a slice of data. However, I am not clear how does this slice,
offset1:-offset1
, work?  Besides, I am not sure which dimensions of original data should be changed.

For instance, I tried an array of data, which is of shape 
(1,300,300,1)
. After setting up 
offset1=0   and offset2=0
I found the
crop_data
resulted from this
crop_data = data[:,offset1:-offset1, offset2:-offset2]
will have shape 
(1,0,0,1)
. I do not know why is that?
Reply
#2
(Nov-15-2016, 05:06 AM)winecoding Wrote: crop_data = data[:,offset1:-offset1, offset2:-offset2]
This doesnt look like proper slicing at all. With this code you should get an error such as

>>> 'sdfgsdfsgshdffsfsdfdhdfghajadjhg'[:,5:-5,-10:-10]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: string indices must be integers, not tuple
Recommended Tutorials:
Reply


Forum Jump:

User Panel Messages

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