执行数据集的快速傅里叶变换后的输出数组

时间:2016-02-10 23:41:44

标签: python numpy fft

我试图对我拥有的数据集执行傅立叶变换,然后分别编写其实部和虚部。

这是我的代码:

import sys,string
import numpy as np
from math import *
import fileinput
from scipy.fftpack import fft, ifft

temparray = []

for i in range(200000):
    line = sys.stdin.readline() ## reads data from a text file
    fields = map(float,line.split())
    temparray.append(fields)
acf = sum(temparray,[]) ## I need to do this as the appended array from above is nested
y = np.fft.fft(acf)
z = (y.real,y.imag)
print z

我得到的输出如下:

(array([ 2600.36368107, 2439.50426935, 1617.52631545, ..., 1575.78483016, 1617.52631545, 2439.50426935]), array([ 0. , -767.19967198, -743.75183367, ..., 726.45052092, 743.75183367, 767.19967198]))

看起来它只打印前几个和最后几个值,完全跳过它们之间的所有内容。有人可以告诉我为什么会这样吗?

由于

1 个答案:

答案 0 :(得分:2)

正如其他人所指出的那样,包括

的修改版本
>>> np.set_printoptions(edgeitems=5,linewidth=80,precision=2,suppress=True,threshold=10) 
>>> a = np.arange(0,100.)
>>> 
>>> a
array([  0.,   1.,   2.,   3.,   4., ...,  95.,  96.,  97.,  98.,  99.])
>>> np.set_printoptions(edgeitems=5,linewidth=80,precision=2,suppress=True,threshold=100) 
>>> a
array([  0.,   1.,   2.,   3.,   4.,   5.,   6.,   7.,   8.,   9.,  10.,  11.,
        12.,  13.,  14.,  15.,  16.,  17.,  18.,  19.,  20.,  21.,  22.,  23.,
        24.,  25.,  26.,  27.,  28.,  29.,  30.,  31.,  32.,  33.,  34.,  35.,
        36.,  37.,  38.,  39.,  40.,  41.,  42.,  43.,  44.,  45.,  46.,  47.,
        48.,  49.,  50.,  51.,  52.,  53.,  54.,  55.,  56.,  57.,  58.,  59.,
        60.,  61.,  62.,  63.,  64.,  65.,  66.,  67.,  68.,  69.,  70.,  71.,
        72.,  73.,  74.,  75.,  76.,  77.,  78.,  79.,  80.,  81.,  82.,  83.,
        84.,  85.,  86.,  87.,  88.,  89.,  90.,  91.,  92.,  93.,  94.,  95.,
        96.,  97.,  98.,  99.])

np.set_printoptions(edgeitems=3,linewidth=80,precision=2,suppress=True,threshold=5)

或许将阈值设置为某个非常大的数字。

附录

如果我没有说上面最简单的解决方案是简单使用

,那将是我的疏忽
>>> list(a)

你不在乎是否可以直观地返回一个数组。