0

There is a multi-dimensional array, e.g., data is of shape (1,320,320,1)

I once saw a function which uses

x=data[:,c:-c,d:-d]

I am not very clear about what does this mean, my original understanding is that x will keep data's first two dimensions, and take a slice from data on the third and fouth dimension. But when c=0,d=0. The resulting x is of shape (1,0,0,1). I am confused about this. Thanks.

Edited by Reverend Jim: changed "pytho" to "python" in thread title

2
Contributors
1
Reply
21
Views
9 Months
Discussion Span
Last Post by slate
1

I am not very clear about what does this mean, my original understanding is that x will keep data's first two dimensions, and take a slice from data on the third and fouth dimension.

It keeps the first and fourth dimension and slices the two inbetween.

x=data[:,c:-c,d:-d]

The first dimension is unchanged. If c=d=0, then the second and third dimension is between 0 and 0-1=-1. So no item is selected.
The last one is not mentioned, so it stays unchanged.

The same behaviour on a one dimensional python array (list):

>>> data=list(range(10))
>>> c=0
>>> data[c:-c]
[]
>>> c=2
>>> data[c:-c]
[2, 3, 4, 5, 6, 7]
>>>

Edited by slate

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.