fht icon indicating copy to clipboard operation
fht copied to clipboard

Consider using asarray rather than astype

Open esc opened this issue 11 years ago • 1 comments

If you do not need to cast the array, it is faster to use asarray rather than astype since asarray will be much less expensive if not cast is needed.

In [16]: a = np.arange(1e8, dtype='float32')

In [17]: %timeit a.astype('float32')
10 loops, best of 3: 200 ms per loop

In [18]: %timeit np.asarray(a, dtype='float32')
1000000 loops, best of 3: 965 ns per loop

In [19]: %timeit a.astype('float64')
1 loops, best of 3: 270 ms per loop

In [20]: %timeit np.asarray(a, dtype='float64')
1 loops, best of 3: 269 ms per loop

esc avatar Jul 30 '14 17:07 esc

For example https://github.com/esc/fht/blob/master/fht/fht.py#L77

esc avatar Jul 30 '14 17:07 esc