numpy
numpy copied to clipboard
BUG: Array order is ignored when array only has one column.
Describe the issue:
Many functions such as np.ones allow you to specify whether the data is stored by row and then column, or column and then row. Seemingly, the default option is always chosen when there is only one column of data, regardless of what is specified.
Reproduce the code example:
import numpy as np
A = np.ones((4, 2))
A.resize((4, 3))
print(A)
B = np.ones((4, 2), order='F')
B.resize((4, 3))
print(B)
C = np.ones((4, 1))
C.resize((4, 2))
print(C)
#does not behave as expected
D = np.ones((4, 1), order='F')
D.resize((4, 2))
print(D)
Error message:
No response
NumPy/Python version information:
1.23.1 3.10.5 (main, Jun 7 2022, 21:08:59) [GCC 11.3.0]
This does seem like a bug, the memory layout seems to be respected when the data is only f-contiguous, but not when it is both F & C contiguous (i.e. the 1-D case). I'm not sure what the intended behavior is though - honestly I was a bit surprised that example B
worked. At the very least this should be documented.
You cannot infer desired order from an array which has both orders. The thing to do is probably to add an order="A"
argument, and in this case the user could provide order="F"
.
(Although, I would generally avoid resizing if possible since it is only safe on freshly created arrays.)