arrayfire-python icon indicating copy to clipboard operation
arrayfire-python copied to clipboard

Return fixed length tuple from array.dims()?

Open HarryStorbacka opened this issue 6 years ago • 1 comments

Hi,

Could you consider changing array.dims() to return a fixed length tuple, like (3,4,1,1)? Currently it's necessary to check the length of the returned tuple before indexing it to get the size of a specific dimension.

>>> import arrayfire as af
>>> aa = af.randu(3,4,1)
>>> aa.dims()
(3, 4)
>>> bb = af.randu(3,4,2)
>>> bb.dims()
(3, 4, 2)
>>>

Something like this...

>>> def dims(arr):
>>>    return arr.dims() + ((1,)*(4-len(arr.dims())))

>>> dims(aa)
(3,4,1,1)

HarryStorbacka avatar Jan 12 '18 13:01 HarryStorbacka

@HarryStorbacka a workaround would be af.dim4(*a.shape)

pavanky avatar Jan 12 '18 17:01 pavanky