
Hi all, I got a weird output from the following script: import numpy as np U = np.zeros(1, dtype=[('x', np.float32, (4,4))]) U[0] = np.eye(4) print U[0] # output: ([[0.0, 1.875, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 1.875], [0.0, 0.0, 0.0, 0.0]],) U[0] = np.eye(4, dtype=np.float32) print U[0] # output: ([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]],) The first output is obviously wrong. Can anyone confirm ? (using numpy 1.7.1 on osx 10.8.3) Nicolas

On Wed, May 22, 2013 at 10:07 AM, Nicolas Rougier
U = np.zeros(1, dtype=[('x', np.float32, (4,4))])
U[0] = np.eye(4) print U[0] # output: ([[0.0, 1.875, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 1.875], [0.0, 0.0, 0.0, 0.0]],)
I get the same thing. Note: In [86]: U[0].shape Out[86]: () it's a rank-zero array, not a 4X4 array -- some odd tings can happen there... This works: In [94]: U = np.zeros(1, dtype=[('x', np.float32, (4,4))]) In [95]: U['x'][0] = np.eye(4) In [96]: U Out[96]: array([ ([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]],)], dtype=[('x', '<f4', (4, 4))]) Not that the first version isn't a bug! -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov

Hi, FWIW, apparently bug related to dtype of np.eye(.) On Wed, May 22, 2013 at 8:07 PM, Nicolas Rougier <Nicolas.Rougier@inria.fr>wrote:
Hi all,
I got a weird output from the following script:
import numpy as np
U = np.zeros(1, dtype=[('x', np.float32, (4,4))])
U[0] = np.eye(4) print U[0] # output: ([[0.0, 1.875, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 1.875], [0.0, 0.0, 0.0, 0.0]],)
U[0] = np.eye(4, dtype=np.float32) print U[0] # output: ([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]],)
The first output is obviously wrong. Can anyone confirm ? (using numpy 1.7.1 on osx 10.8.3)
In []: sys.version Out[]: '2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]' In []: np.__version__ Out[]: '1.6.0' In []: U= np.zeros(1, dtype= [('x', np.float32, (4, 4))]) In []: U[0]= np.eye(4) In []: U Out[]: array([ ([[0.0, 1.875, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 1.875], [0.0, 0.0, 0.0, 0.0]],)], dtype=[('x', '<f4', (4, 4))]) In []: U[0]= np.eye(4, dtype= np.float32) In []: U Out[]: array([ ([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]],)], dtype=[('x', '<f4', (4, 4))]) and In []: sys.version Out[]: '3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64 bit (AMD64)]' In []: np.__version__ Out[]: '1.7.0rc1' In []: U= np.zeros(1, dtype= [('x', np.float32, (4, 4))]) In []: U[0]= np.eye(4) In []: U Out[17]: array([ ([[0.0, 1.875, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 1.875], [0.0, 0.0, 0.0, 0.0]],)], dtype=[('x', '<f4', (4, 4))]) U[0]= np.eye(4, dtype= np.float32) In []: U Out[]: array([ ([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]],)], dtype=[('x', '<f4', (4, 4))]) My 2 cents, -eat
Nicolas _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion

Thanks, I filed a new issue on the bug tracker. Nicolas On May 22, 2013, at 8:15 PM, eat <e.antero.tammi@gmail.com> wrote:
Hi,
FWIW, apparently bug related to dtype of np.eye(.)
On Wed, May 22, 2013 at 8:07 PM, Nicolas Rougier <Nicolas.Rougier@inria.fr> wrote:
Hi all,
I got a weird output from the following script:
import numpy as np
U = np.zeros(1, dtype=[('x', np.float32, (4,4))])
U[0] = np.eye(4) print U[0] # output: ([[0.0, 1.875, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 1.875], [0.0, 0.0, 0.0, 0.0]],)
U[0] = np.eye(4, dtype=np.float32) print U[0] # output: ([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]],)
The first output is obviously wrong. Can anyone confirm ? (using numpy 1.7.1 on osx 10.8.3) In []: sys.version Out[]: '2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]' In []: np.__version__ Out[]: '1.6.0' In []: U= np.zeros(1, dtype= [('x', np.float32, (4, 4))])
In []: U[0]= np.eye(4) In []: U Out[]: array([ ([[0.0, 1.875, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 1.875], [0.0, 0.0, 0.0, 0.0]],)], dtype=[('x', '<f4', (4, 4))])
In []: U[0]= np.eye(4, dtype= np.float32) In []: U Out[]: array([ ([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]],)], dtype=[('x', '<f4', (4, 4))])
and In []: sys.version Out[]: '3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64 bit (AMD64)]' In []: np.__version__ Out[]: '1.7.0rc1' In []: U= np.zeros(1, dtype= [('x', np.float32, (4, 4))])
In []: U[0]= np.eye(4) In []: U Out[17]: array([ ([[0.0, 1.875, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 1.875], [0.0, 0.0, 0.0, 0.0]],)], dtype=[('x', '<f4', (4, 4))])
U[0]= np.eye(4, dtype= np.float32)
In []: U Out[]: array([ ([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]],)], dtype=[('x', '<f4', (4, 4))])
My 2 cents, -eat
Nicolas _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion

On Wed, May 22, 2013 at 11:15 AM, eat <e.antero.tammi@gmail.com> wrote:
FWIW, apparently bug related to dtype of np.eye(.)
sort of -- the issue shows up when assigning a float64 array (default for eye()) to a rank-0 array with a custom dtype that has a single object filed that is an array....numpy should do the right thing there. If you pull the arra yout of the custom dtype object, it does do the right thing. See the example I posted earlier. -Chris
On Wed, May 22, 2013 at 8:07 PM, Nicolas Rougier <Nicolas.Rougier@inria.fr> wrote:
Hi all,
I got a weird output from the following script:
import numpy as np
U = np.zeros(1, dtype=[('x', np.float32, (4,4))])
U[0] = np.eye(4) print U[0] # output: ([[0.0, 1.875, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 1.875], [0.0, 0.0, 0.0, 0.0]],)
U[0] = np.eye(4, dtype=np.float32) print U[0] # output: ([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]],)
The first output is obviously wrong. Can anyone confirm ? (using numpy 1.7.1 on osx 10.8.3)
In []: sys.version Out[]: '2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]' In []: np.__version__ Out[]: '1.6.0' In []: U= np.zeros(1, dtype= [('x', np.float32, (4, 4))])
In []: U[0]= np.eye(4) In []: U Out[]: array([ ([[0.0, 1.875, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 1.875], [0.0, 0.0, 0.0, 0.0]],)], dtype=[('x', '<f4', (4, 4))])
In []: U[0]= np.eye(4, dtype= np.float32) In []: U Out[]: array([ ([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]],)], dtype=[('x', '<f4', (4, 4))])
and In []: sys.version Out[]: '3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64 bit (AMD64)]' In []: np.__version__ Out[]: '1.7.0rc1' In []: U= np.zeros(1, dtype= [('x', np.float32, (4, 4))])
In []: U[0]= np.eye(4) In []: U Out[17]: array([ ([[0.0, 1.875, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 1.875], [0.0, 0.0, 0.0, 0.0]],)], dtype=[('x', '<f4', (4, 4))])
U[0]= np.eye(4, dtype= np.float32)
In []: U Out[]: array([ ([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]],)], dtype=[('x', '<f4', (4, 4))])
My 2 cents, -eat
Nicolas _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
-- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov
participants (3)
-
Chris Barker - NOAA Federal
-
eat
-
Nicolas Rougier