Contiguous Array

Ankit Agrawal aaaagrawal at gmail.com
Wed Jul 31 04:15:35 EDT 2013


Hi Marc,


On Wed, Jul 31, 2013 at 1:09 PM, Marc de Klerk <deklerkmc at 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... at 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 at googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20130731/8883dbb8/attachment.html>


More information about the scikit-image mailing list