Change of behavior in flatten between 1.0.4 and 1.1

Hi -- I have noticed a change in the behavior of numpy.flatten(True) between NumPy 1.0.4 and NumPy 1.1. The change affects 3D arrays. I am wondering if this is a bug or a feature. Here's the change. Note that the output from flatten(True) is different between 1.0.4 and 1.1. ======= First the preliminary set up: ======= In [3]: A = numpy.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]]) In [4]: A Out[4]: array([[[ 1, 2], [ 3, 4]], [[ 5, 6], [ 7, 8]], [[ 9, 10], [11, 12]]]) ======= Now the change: Numpy 1.0.4 ======= In [5]: A.flatten() Out[5]: array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) In [6]: A.flatten(True) Out[6]: array([ 1, 5, 9, 2, 6, 10, 3, 7, 11, 4, 8, 12]) ======= Numpy 1.1 ======= In [4]: A.flatten() Out[4]: array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) In [5]: A.flatten(True) Out[5]: array([ 1, 5, 9, 3, 7, 11, 2, 6, 10, 4, 8, 12]) Note that the output of A.flatten(True) is different. Is this a bug or a feature? Cheers, Stuart Brorson Interactive Supercomputing, inc. 135 Beaver Street | Waltham | MA | 02452 | USA http://www.interactivesupercomputing.com/

Tue, 01 Jul 2008 17:18:55 -0400, Stuart Brorson wrote:
Hi --
I have noticed a change in the behavior of numpy.flatten(True) between NumPy 1.0.4 and NumPy 1.1. The change affects 3D arrays. I am wondering if this is a bug or a feature.
Here's the change. Note that the output from flatten(True) is different between 1.0.4 and 1.1.
I think it was this one http://scipy.org/scipy/numpy/ticket/676 The rationale was to make the output from .flatten(1) to be equal to interpreting the data as it would appear in a multidimensional Fortran array (equivalent to reshape(a, (prod(a.shape),), order='F'), IIRC). In 1.0.4 a.flatten(1) only swapped the two first axes and then flattened in C-order. In 1.1, a.flatten(1) == a.transpose().flatten(). To me, it appeared that the behavior in 1.0.4 was incorrect, so I filed the bug (after being bitten by it in real code...) and submitted a patch that got applied. -- Pauli Virtanen
======= First the preliminary set up: =======
In [3]: A = numpy.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]])
In [4]: A
Out[4]:
array([[[ 1, 2], [ 3, 4]],
[[ 5, 6], [ 7, 8]],
[[ 9, 10], [11, 12]]])
======= Now the change: Numpy 1.0.4 =======
In [5]: A.flatten()
Out[5]: array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
In [6]: A.flatten(True)
Out[6]: array([ 1, 5, 9, 2, 6, 10, 3, 7, 11, 4, 8, 12])
Here the two first dimensions are swapped and data is interpreted in C- order.
======= Numpy 1.1 =======
In [4]: A.flatten()
Out[4]: array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
In [5]: A.flatten(True)
Out[5]: array([ 1, 5, 9, 3, 7, 11, 2, 6, 10, 4, 8, 12])
Here dimensions are transposed, and data is interpreted in C-order. -- Pauli Virtanen

On Tue, 1 Jul 2008, Pauli Virtanen wrote:
Tue, 01 Jul 2008 17:18:55 -0400, Stuart Brorson wrote:
I have noticed a change in the behavior of numpy.flatten(True) between NumPy 1.0.4 and NumPy 1.1. The change affects 3D arrays. I am wondering if this is a bug or a feature.
[...]
To me, it appeared that the behavior in 1.0.4 was incorrect, so I filed the bug (after being bitten by it in real code...) and submitted a patch that got applied.
OK, it's a feature. Thanks for the reply! Cheers, Stuart Brorson Interactive Supercomputing, inc. 135 Beaver Street | Waltham | MA | 02452 | USA http://www.interactivesupercomputing.com/
participants (2)
-
Pauli Virtanen
-
Stuart Brorson