473,323 Members | 1,551 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,323 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 3550
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.