473,372 Members | 1,059 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 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 3551
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

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

Similar topics

6
by: Foxy Kav | last post by:
Hi, another question from me again, i was just wondering if anyone could give me a quick example of reading data from a file then placing the data into an array for some manipulation then reading...
8
by: Yeow | last post by:
hello, i was trying to use the fread function on SunOS and ran into some trouble. i made a simple test as follows: i'm trying to read in a binary file (generated from a fortran code) that...
4
by: Jens Mittag | last post by:
Hi! In my code, I have an array of a structure, which I want to save to a binary file. When the array is just created, everything works fine, but when I change contents of the array, saving...
1
by: Jón Sveinsson | last post by:
Hello everyone I have been able to read data from binary files to filestrean, the data in the files are structured, what I'm trying to do is to loop through the binary files and add data to my...
7
by: John Dann | last post by:
I'm trying to read some binary data from a file created by another program. I know the binary file format but can't change or control the format. The binary data is organised such that it should...
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
11
by: Freddy Coal | last post by:
Hi, I'm trying to read a binary file of 2411 Bytes, I would like load all the file in a String. I make this function for make that: '-------------------------- Public Shared Function...
6
by: jcasique.torres | last post by:
Hi everyboy. I trying to create a C promang in an AIX System to read JPG files but when it read just the first 4 bytes when it found a DLE character (^P) doesn't read anymore. I using fread...
3
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, I'm trying to write an array of structures named myStructArray to a binary file and later on read it back. Although I could complete the entire project in C in about 2 minutes, I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.