[Numpy-discussion] Array descriptors not compared correctly causes asarray to copy data

Albert Strasheim fullung at gmail.com
Wed May 3 04:18:01 EDT 2006


Hello all

There seems to be a problem with asarray when using more than one instance
of an equivalent dtype.

Example code:

import numpy as N
print N.__version__
import time
a = N.dtype({'names' : ['i', 'j'], 'formats' : [N.float64, N.float64]})
b = N.dtype({'names' : ['i', 'j'], 'formats' : [N.float64, N.float64]})
print a == b
print a.descr == b.descr
_starttime = time.clock()
arr = N.zeros((5000,1000), dtype=a)
for x in arr:
    y = N.asarray(x, dtype=a)
print 'done in %f seconds' % (time.clock() - _starttime,)
_starttime = time.clock()
for x in arr:
    y = N.asarray(x, dtype=b)
print 'done in %f seconds' % (time.clock() - _starttime,)

On my system I get the following result:

0.9.7.2462
False
True
done in 0.153871 seconds
done in 8.726785 seconds

So while the descrs are equal, Python doesn't seem to think that the dtypes
are which is probably causing the problem.

Trac ticket at http://projects.scipy.org/scipy/numpy/ticket/94.

Regards,

Albert





More information about the NumPy-Discussion mailing list