2

I'm trying to perform a fourier transform of a data set that I have and subsequently writing its real and imaginary parts separately.

This is my code:

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

The output that I get is as follows:

(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]))

It looks like its only printing the first few and last few values, completely skipping everything in between. Can anybody please tell me why this is happening?

Thanks

  • 5
    Are you just referring to the fact that numpy doesn't display the whole thing when you print it? That's done so that large arrays don't completely fill the output. There's a setting you can change, see here: http://stackoverflow.com/questions/1987694/print-the-full-numpy-array – Jezzamon Feb 10 '16 at 23:47

1 Answers1

2

As others have indicated, include a modified version of

>>> 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)

perhaps setting threshold to some very large number.

Addendum

I would be remiss if I didn't state that the simplest solution to the above is to simple use

>>> list(a)

should you not care whether an array is visually returned or not.