1 | initial version |
@Santhosh1, your experiment is unfair because ima2 = ima[..., ::-1]
permutes only indices but not the data.
That means to check identical operations you have to call numpy.ascontiguousarray
In example,
import numpy as np
a = np.zeros([4, 5, 3], dtype=np.uint8)
a[:,:,0] = ord('b')
a[:,:,1] = ord('g')
a[:,:,2] = ord('r')
print a
print a.flags
print a.data
gives
[[[ 98 103 114]
[ 98 103 114]
[ 98 103 114]
[ 98 103 114]
[ 98 103 114]]
[[ 98 103 114]
[ 98 103 114]
[ 98 103 114]
[ 98 103 114]
[ 98 103 114]]
[[ 98 103 114]
[ 98 103 114]
[ 98 103 114]
[ 98 103 114]
[ 98 103 114]]
[[ 98 103 114]
[ 98 103 114]
[ 98 103 114]
[ 98 103 114]
[ 98 103 114]]]
C_CONTIGUOUS : True
F_CONTIGUOUS : False
OWNDATA : True
WRITEABLE : True
ALIGNED : True
WRITEBACKIFCOPY : False
UPDATEIFCOPY : False
bgrbgrbgrbgrbgrbgrbgrbgrbgrbgrbgrbgrbgrbgrbgrbgrbgrbgrbgrbgr
But
a = a[:,:,::-1]
print a
print a.flags
print a.data
cannot get raw data because an array became discontinuous
[[[114 103 98]
[114 103 98]
[114 103 98]
[114 103 98]
[114 103 98]]
[[114 103 98]
[114 103 98]
[114 103 98]
[114 103 98]
[114 103 98]]
[[114 103 98]
[114 103 98]
[114 103 98]
[114 103 98]
[114 103 98]]
[[114 103 98]
[114 103 98]
[114 103 98]
[114 103 98]
[114 103 98]]]
C_CONTIGUOUS : False
F_CONTIGUOUS : False
OWNDATA : False
WRITEABLE : True
ALIGNED : True
WRITEBACKIFCOPY : False
UPDATEIFCOPY : False
Traceback (most recent call last):
File "test.py", line 16, in <module>
print a.data
AttributeError: cannot get single-segment buffer for discontiguous array