BUG: ascontiguousarray and asfortranarray make 0d scalars into 1d arrays
See original GitHub issueNot sure if this is intended behavior or a bug, but I had been under the assumption that the result of np.ascontiguousarray
would be the same shape as the input. This is true except in the case of scalars.
>>> scalar = np.float64(3.0)
>>> np.asarray(scalar).shape # asarray doesn't change shape
()
>>> np.ascontiguousarray(scalar).shape # ascontiguousarray does
(1,)
If this is what should be expected, it would be helpful to document this in its docstring.
Thanks!
Issue Analytics
- State:
- Created 9 years ago
- Comments:19 (17 by maintainers)
Top Results From Across the Web
is there a pythonic way to change scalar and 0d-array to 1d ...
A quick way to change a scalar or a 0d array to a 1d array using np.reshape after checking the dimension with np.ndim...
Read more >numpy.ascontiguousarray — NumPy v1.24 Manual
In this case, it ensures the creation of an array object compatible with that passed in via this argument. New in version 1.20.0....
Read more >Python usage notes - Numpy, scipy - Helpful
Generating 1D arrays. Your options to generate such matrices include: numpy.arange(). , similar to python's range() but produces a numpy array.
Read more >NumPy Documentation — NumPy v1.19 Manual
How to convert a 1D array into a 2D array (how to add a new axis to an array) · Indexing and slicing...
Read more >arrays - astro.udec.cl
Copies the first data point of the array to a standard Python scalar and ... Takes a sequence of 1D arrays and stacks...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
How about we just deprecate
np.asfortranarray
andnp.ascontiguousarray
in favor ofnp.asarray(..., order='C')
andnp.asarray(..., order='F')
, since the former are:Thinking more, I suspect this is intended for producing arrays for C and, in the case of asfortrancontiguous, for Fortran functions. Allowing zero dimensional arrays might well cause problems.