1

我想将 scipy.fftpack 中的 dct 功能与 numpy float64 数组一起使用。但是,它似乎只针对 np.float32 实现。我有什么快速的解决方法可以完成这项工作吗?我很快调查了它,但我不确定所有的依赖关系。所以,在搞砸一切之前,我想我会在这里寻求提示!

到目前为止,我唯一找到的就是这个链接: http: //mail.scipy.org/pipermail/scipy-svn/2010-September/004197.html

提前致谢。

这是它引发的 ValueError:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-12-f09567c28e37> in <module>()
----> 1 scipy.fftpack.dct(c[100])

/usr/local/Cellar/python/2.7.3/lib/python2.7/site-packages/scipy/fftpack/realtransforms.pyc in dct(x, type, n, axis, norm, overwrite_x)
    118         raise NotImplementedError(
    119               "Orthonormalization not yet supported for DCT-I")
--> 120     return _dct(x, type, n, axis, normalize=norm, overwrite_x=overwrite_x)
    121 
    122 def idct(x, type=2, n=None, axis=-1, norm=None, overwrite_x=0):

/usr/local/Cellar/python/2.7.3/lib/python2.7/site-packages/scipy/fftpack/realtransforms.pyc in _dct(x, type, n, axis, overwrite_x, normalize)
    215             raise ValueError("Type %d not understood" % type)
    216     else:
--> 217         raise ValueError("dtype %s not supported" % tmp.dtype)
    218 
    219     if normalize:

ValueError: dtype >f8 not supported
4

1 回答 1

5

The problem is not the double precision. Double precision is of course supported. The problem is that you have a little endian computer and (maybe loading a file from a file?) have big endian data, note the > in dtype >f8 not supported. It seems you will simply have to cast it to native double yourself. If you know its double precision, you probably just want to convert everytiong to your native order once:

c = c.astype(float)

Though I guess you could also check c.dtype.byteorder which I think should be '=', and if, switch... something along:

if c.dtype.byteorder != '=':
    c = c.astype(c.dtype.newbyteorder('=')) 

Which should work also if you happen to have single precision or integers...

于 2012-09-06T21:02:00.677 回答