scipy、fftpack 和 float64 [英] scipy, fftpack and float64
问题描述
我想将 scipy.fftpack 中的 dct 功能与 numpy float64 数组一起使用.但是,它似乎仅适用于 np.float32.是否有任何快速解决方法可以完成此操作?我很快地查看了它,但我不确定所有的依赖项.所以,在搞砸一切之前,我想我会在这里寻求提示!
I would like to use the dct functionality from the scipy.fftpack with an array of numpy float64. However, it seems it is only implemented for np.float32. Is there any quick workaround I could do to get this done? I looked into it quickly but I am not sure of all the dependencies. So, before messing everything up, I thought I'd ask for tips here!
到目前为止我唯一发现的就是这个链接:http://mail.scipy.org/pipermail/scipy-svn/2010-September/004197.html
The only thing I have found so far about this is this link : http://mail.scipy.org/pipermail/scipy-svn/2010-September/004197.html
提前致谢.
这是它引发的 ValueError:
Here is the ValueError it raises:
---------------------------------------------------------------------------
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
推荐答案
问题不在于双精度.当然支持双精度.问题是您有一台小端计算机并且(也许从文件中加载文件?)有大端数据,请注意 dtype >f8 not supported
中的 >
>.看来您只需要自己将其转换为原生 double 即可.如果您知道它的双精度,您可能只想将所有内容转换为您的本机顺序一次:
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)
虽然我猜你也可以检查 c.dtype.byteorder
,我认为应该是 '='
,如果,切换......一些东西:>
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...
这篇关于scipy、fftpack 和 float64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!