472,125 Members | 1,603 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,125 software developers and data experts.

Reading binary into complex array

Dear All,

Ive started learning Python couple of hours ago, after working with IDL for
a long time and I have a question I hope you would not mind answering.
I have a binary file that I would like to read into a 512point complex array
and print couple of points, say first and the fifth terms.

If you are familiar with Matlab or IDL, the corresponding IDL commands
would be something like:
data = complexarr(512)
openr, lun, 'datafile', /get_lun
readu, lun, data

How can i do the same in Python? Thanks in advance for your help.
Aug 9 '07 #1
3 3473
bartonc
6,596 Expert 4TB
You'll need to use the struct module to convert your data. Post an example of your array structure for further help.

Thanks for joining.
Aug 10 '07 #2
I have tried the following:

import array
data = array.array('f')
f = open('filename','rb')
data.fromfile(f, 6)
print data

The result is:
array('f', [1002.02490234375, 10.442339897155762, -251.11215209960937, -1295.44384765625, -645.1199951171875, -18.742809295654297])

What I was hoping to get was an array of 3 complex points with the
following real and img parts:
(1002.02, 10.4423) ( -251.112, -1295.44) (-645.120, -18.7428)

Eventually what I would like to do is to apply FFT on the complex array.
Thanks for your help.
Aug 10 '07 #3
bartonc
6,596 Expert 4TB
I have tried the following:

import array
data = array.array('f')
f = open('filename','rb')
data.fromfile(f, 6)
print data

The result is:
array('f', [1002.02490234375, 10.442339897155762, -251.11215209960937, -1295.44384765625, -645.1199951171875, -18.742809295654297])

What I was hoping to get was an array of 3 complex points with the
following real and img parts:
(1002.02, 10.4423) ( -251.112, -1295.44) (-645.120, -18.7428)

Eventually what I would like to do is to apply FFT on the complex array.
Thanks for your help.
Then you'll definitely want to get SciPy. SciPy arrays can be created to suit your needs and the FFT is implemented in C, but called like a built-in function.
Aug 10 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Foxy Kav | last post: by
8 posts views Thread by Yeow | last post: by
1 post views Thread by Jón Sveinsson | last post: by
7 posts views Thread by John Dann | last post: by
6 posts views Thread by arne.muller | last post: by
11 posts views Thread by Freddy Coal | last post: by
6 posts views Thread by jcasique.torres | last post: by
3 posts views Thread by =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.