What does ravel
stand for in NumPy
?
Sometimes, it is a bit harder to remember a function name that the name has nothing to do with its description.
CodePudding user response:
The dictionary meaning for ravel
is
to become unwoven, untwisted, or unwound
We tend to use unravel
in same way
to separate or undo the texture of : UNRAVEL
https://www.merriam-webster.com/dictionary/ravel
In numpy
flatten
does the same thing, except it always makes a copy. ravel
is more like reshape(-1)
, returning a view
where possible
It's use for computational arrays may trace back to apl
in the 1960s.
https://aplwiki.com/wiki/Ravel.
CodePudding user response:
ravel
means the same as unravel
- to become unwoven, untwisted, or unwound
As for numpy ravel - a 1-D array, containing the elements of the input, is returned. So if you provide a 2D array to ravel
, it will be unwoven, untwisted or unwound, to become a 1D array.
x = np.array([[1, 2, 3],
[4, 5, 6]])
np.ravel(x)
OUTPUT:
array([1, 2, 3, 4, 5, 6])