On Wed, May 22, 2013 at 11:15 AM, eat <e.antero.ta...@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.roug...@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.bar...@noaa.gov
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to