In [1]: x = np.arange(20, dtype=np.uint8).reshape((4,5))
In [2]: x
Out[2]:
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19]], dtype=uint8)
In [3]: x.strides
Out[3]: (5, 1)
In [4]: y = x.T[1::2]
In [5]: y.strides
Out[5]: (2, 5)
In [6]: y
Out[6]:
array([[ 1, 6, 11, 16],
[ 3, 8, 13, 18]], dtype=uint8)
In [7]: y[1, 1] = 45
In [8]: x
Out[8]:
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 45, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19]], dtype=uint8)
In [10]: np.ravel(y)
Out[10]: array([ 1, 6, 11, 16, 3, 45, 13, 18], dtype=uint8)
In [11]: z = np.ascontiguousarray(y)
In [12]: z
Out[12]:
array([[ 1, 6, 11, 16],
[ 3, 45, 13, 18]], dtype=uint8)
In [13]: z.strides
Out[13]: (4, 1)
In [14]: z[0, 0] = 72
In [15]: x
Out[15]:
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 45, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19]], dtype=uint8)
In [16]: z
Out[16]:
array([[72, 6, 11, 16],
[ 3, 45, 13, 18]], dtype=uint8)
In [19]: a = np.ravel(x)
In [20]: a[0] = 72
In [21]: x
Out[21]:
array([[72, 1, 2, 3, 4],
[ 5, 6, 7, 45, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19]], dtype=uint8)
In [22]: b = np.ascontiguousarray(x)
In [23]: b is x
Out[23]: True
In [25]: b[3, 4] = 0
In [26]: x
Out[26]:
array([[72, 1, 2, 3, 4],
[ 5, 6, 7, 45, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 0]], dtype=uint8)
Hi Marc,
On Wed, Jul 31, 2013 at 1:09 PM, Marc de Klerk <deklerkmc@gmail.com> wrote:Hi guys,I've been using np.ravel(). This morning I tried to lookup the difference between np.ravel() and np.ascontiguousarray(). Does anybody know?I am not sure if this helps as I don't know your purpose for using np.ravel / np.ascontiguousarray. I got to know about the ndarray.flags method yesterday from Stefan while discussion on this PR.In [15]: a = np.arange(20).reshape((4,5))In [16]: aOut[16]:array([[ 0, 1, 2, 3, 4],[ 5, 6, 7, 8, 9],[10, 11, 12, 13, 14],[15, 16, 17, 18, 19]])In [17]: a.flagsOut[17]:C_CONTIGUOUS : TrueF_CONTIGUOUS : FalseOWNDATA : FalseWRITEABLE : TrueALIGNED : TrueUPDATEIFCOPY : FalseIn [18]: b = np.ravel(a)In [20]: bOut[20]:array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,17, 18, 19])In [21]: b.flagsOut[21]:C_CONTIGUOUS : TrueF_CONTIGUOUS : TrueOWNDATA : FalseWRITEABLE : TrueALIGNED : TrueUPDATEIFCOPY : FalseHope this helps!!Marc
On Sunday, July 21, 2013 6:37:47 AM UTC+2, Chintak Sheth wrote:Hi Ronnie,
On Jul 21, 2013 10:00 AM, "Ronnie Ghose" <ronnie...@gmail.com> wrote:
>
> So in skimage/colors why does it matter if the array is contiguous? Is this for Cython operations later?
>Yeah it is mainly for using memory views in Cython which is initialized as C contiguous.
`cdef some_type[:. ::1] var_name`In thus case ::1 is for C contiguous.
Chintak
--
You received this message because you are subscribed to the Google Groups "scikit-image" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scikit-image+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "scikit-image" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scikit-image+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.