[Numpy-discussion] How to get the shape of an array slice without doing it

josef.pktd@gmai... josef.pktd@gmai...
Fri Jan 29 11:53:46 CST 2010


On Fri, Jan 29, 2010 at 12:48 PM,  <josef.pktd@gmail.com> wrote:
> On Fri, Jan 29, 2010 at 12:32 PM, David Huard <david.huard@gmail.com> wrote:
>> On Fri, Jan 29, 2010 at 12:10 PM,  <josef.pktd@gmail.com> wrote:
>>> On Fri, Jan 29, 2010 at 11:49 AM, David Huard <david.huard@gmail.com> wrote:
>>>> Hi,
>>>>
>>>> I have a 4D "array" with a given shape, but the array is never
>>>> actually created since it is large and distributed over multiple
>>>> binary files. Typical usage would be to take slices across the 4D
>>>> array.
>>>>
>>>> I'd like to know what the shape of the resulting array would be if I
>>>> took a slice out of it.
>>>> That is, let's say my 4D array is A, I'd like to know
>>>>
>>>> A[ndindex].shape
>>>>
>>>> without actually creating A.
>>>>
>>>> ndindex should support all numpy constructions (integer, boolean,
>>>> array, slice, ...). I am guessing something already exists to do this,
>>>> but I just can't put my finger on it.
>>>
>>> trying out some things, just because it's a puzzling question
>>>
>>>>>> indi= (slice(2,5), np.arange(2), np.arange(3)[:,None])
>>>>>> np.broadcast(*indi).shape
>>> (3, 2)
>>>
>>> I don't know if this is ok for all possible cases, (and there are some
>>> confusing things with reordering axis, when slices and fancy indexing
>>> is mixed)
>>>
>>
>> Hi josef,
>>
>> Where then do you specify the shape of the A array ?  Maybe an example
>> would be clearer:
>>
>> Let's say A's shape is (10, 1, 5, 20)
>> and the index is [::2, ..., 0]
>>
>> A[::2, ..., 0] shape would be (5, 1, 5)
>>
>> The broadcast idea has potential, I'll toy with it.
>>
>> David
>
> maybe this helps:
>
>>>> np.broadcast(*indi).shape
> (3, 2)
>>>> indi= (slice(slice(8,None,None).indices(10)),np.arange(2), np.arange(3)[:,None])
>>>> np.broadcast(*indi).shape
> (3, 2)
>>>> slice(8,None,None).indices(10)
> (8, 10, 1)
>
> I'm just doing dir(slice) and look up the docs. I never used any of this.
>
> Josef

I forgot about ellipsis, since I never use them,
replace ellipsis by [slice(None)]*ndim or something like this

I don't know how to access an ellipsis directly, is it even possible
to construct an index list that contains an ellipsis?
There is an object for it but I never looked at it.

Josef

>
>
>>
>>
>>
>>> Josef
>>>
>>>
>>>
>>>> Thanks.
>>>>
>>>> David
>>>> _______________________________________________
>>>> NumPy-Discussion mailing list
>>>> NumPy-Discussion@scipy.org
>>>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>>>
>>> _______________________________________________
>>> NumPy-Discussion mailing list
>>> NumPy-Discussion@scipy.org
>>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>>
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion@scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>
>


More information about the NumPy-Discussion mailing list