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? 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<javascript:>> 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
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<https://github.com/scikit-image/scikit-image/pull/668> . In [15]: a = np.arange(20).reshape((4,5)) In [16]: a Out[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.flags Out[17]: C_CONTIGUOUS : True F_CONTIGUOUS : False OWNDATA : False WRITEABLE : True ALIGNED : True UPDATEIFCOPY : False In [18]: b = np.ravel(a) In [20]: b Out[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.flags Out[21]: C_CONTIGUOUS : True F_CONTIGUOUS : True OWNDATA : False WRITEABLE : True ALIGNED : True UPDATEIFCOPY : False Hope 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.
Hi Marc On Wed, Jul 31, 2013 at 9:39 AM, Marc de Klerk <deklerkmc@gmail.com> wrote:
I've been using np.ravel(). This morning I tried to lookup the difference between np.ravel() and np.ascontiguousarray(). Does anybody know?
np.ravel docstring: A 1-D array, containing the elements of the input, is returned. A copy is made only if needed. np.ascontiguousarray: Return a contiguous array in memory (C order). In [13]: x = np.array(([1, 2], [3, 4])) In [14]: np.ravel(x) Out[14]: array([1, 2, 3, 4]) In [15]: np.ascontiguousarray(x) Out[15]: array([[1, 2], [3, 4]]) Since the default "order" parameter for ravel is "C", and 1-D arrays with order "C" can only be contiguous, you happen to get contiguous memory layout. However, if you want to preserve shape, you cannot use ravel. Stéfan
participants (3)
-
Ankit Agrawal
-
Marc de Klerk
-
Stéfan van der Walt