Contiguous Array
Stéfan van der Walt
stefan at sun.ac.za
Wed Jul 31 05:36:49 EDT 2013
Hi Marc
On Wed, Jul 31, 2013 at 9:39 AM, Marc de Klerk <deklerkmc at 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
More information about the scikit-image
mailing list