473,555 Members | 2,290 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

fromfile error on windows, not mac

Hello,
I am using the numpy fromfile function to read binary data from a file
on disk. The problem is that the program runs fine on a Mac, but gives
an error or warning on windows when trying to read the data. I use it
like this:

Signal = zeros((N, 16), dtype=float32)
for sample in range(0, N):
# this function gets the next position in the file to seek to
s = getFilePos(samp le)

# go to the correct location in the file; this IS checked to make
sure it is within the file
mFile.seek(s)

# read the 16 float32 values from the file
D = fromfile(mFile, dtype=numpy.flo at32, 16)

# save D in Signal
Signal[sample, :] = D

This will fail when sample is ~4. If I change the range to (5,N),
skipping the "bad" file location, it will run fine for a few samples,
and then give another error. The message it gives is:
"16 items requested but only 7 read"

So D is a 7x1 vector, and the program dies when it tries to assign D
to the slice of Signal ("ValueError : shape mismatch: objects cannot be
broadcast to a single shape").

On windows, the Python version is 2.5.2, and the most recent numpy and
scipy are being used as well. I tried using Enthought, but it gave
this error as well, in addition to a c runtime error whenever I
imported scipy (which is another post topic...).

Any ideas on what might be causing this? Is there a way to debug the
fromfile function? And, remember, this works perfectly on a Mac. Would
compiling everything (python, scipy, numpy) potentially solve this?

Thanks!
Jul 22 '08 #1
8 1939


jadamwil schrieb:
Hello,
I am using the numpy fromfile function to read binary data from a file
on disk. The problem is that the program runs fine on a Mac, but gives
an error or warning on windows when trying to read the data. I use it
like this:

Signal = zeros((N, 16), dtype=float32)
for sample in range(0, N):
# this function gets the next position in the file to seek to
s = getFilePos(samp le)

# go to the correct location in the file; this IS checked to make
sure it is within the file
mFile.seek(s)

# read the 16 float32 values from the file
D = fromfile(mFile, dtype=numpy.flo at32, 16)

# save D in Signal
Signal[sample, :] = D

This will fail when sample is ~4. If I change the range to (5,N),
skipping the "bad" file location, it will run fine for a few samples,
and then give another error. The message it gives is:
"16 items requested but only 7 read"

So D is a 7x1 vector, and the program dies when it tries to assign D
to the slice of Signal ("ValueError : shape mismatch: objects cannot be
broadcast to a single shape").

On windows, the Python version is 2.5.2, and the most recent numpy and
scipy are being used as well. I tried using Enthought, but it gave
this error as well, in addition to a c runtime error whenever I
imported scipy (which is another post topic...).

Any ideas on what might be causing this? Is there a way to debug the
fromfile function? And, remember, this works perfectly on a Mac. Would
compiling everything (python, scipy, numpy) potentially solve this?
Did you open the file in binary mode ?

Greetings, Uwe
Jul 22 '08 #2
On Jul 22, 2:05*am, Uwe Schmitt <rocksportroc.. .@googlemail.co m>
wrote:
jadamwil schrieb:
Hello,
I am using the numpy fromfile function to read binary data from a file
on disk. The problem is that the program runs fine on a Mac, but gives
an error or warning on windows when trying to read the data. I use it
like this:
Signal = zeros((N, 16), dtype=float32)
for sample in range(0, N):
* # this function gets the next position in the file to seek to
* s = getFilePos(samp le)
* # go to the correct location in the file; this IS checked to make
sure it is within the file
* mFile.seek(s)
* # read the 16 float32 values from the file
* D = fromfile(mFile, dtype=numpy.flo at32, 16)
* # save D in Signal
* Signal[sample, :] = D
This will fail when sample is ~4. If I change the range to (5,N),
skipping the "bad" file location, it will run fine for a few samples,
and then give another error. The message it gives is:
"16 items requested but only 7 read"
So D is a 7x1 vector, and the program dies when it tries to assign D
to the slice of Signal ("ValueError : shape mismatch: objects cannot be
broadcast to a single shape").
On windows, the Python version is 2.5.2, and the most recent numpy and
scipy are being used as well. I tried using Enthought, but it gave
this error as well, in addition to a c runtime error whenever I
imported scipy (which is another post topic...).
Any ideas on what might be causing this? Is there a way to debug the
fromfile function? And, remember, this works perfectly on a Mac. Would
compiling everything (python, scipy, numpy) potentially solve this?

Did you open the file in binary mode ?

Greetings, Uwe
Yes I did. Would that make a difference between a mac and windows?
Thanks
Jul 22 '08 #3
On Jul 22, 8:35*am, jadamwil <jadamwils...@g mail.comwrote:
On Jul 22, 2:05*am, Uwe Schmitt <rocksportroc.. .@googlemail.co m>
wrote:
jadamwil schrieb:
Hello,
I am using the numpy fromfile function to read binary data from a file
on disk. The problem is that the program runs fine on a Mac, but gives
an error or warning onwindowswhen trying to read the data. I use it
like this:
Signal = zeros((N, 16), dtype=float32)
for sample in range(0, N):
* # this function gets the next position in the file to seek to
* s = getFilePos(samp le)
* # go to the correct location in the file; this IS checked to make
sure it is within the file
* mFile.seek(s)
* # read the 16 float32 values from the file
* D = fromfile(mFile, dtype=numpy.flo at32, 16)
* # save D in Signal
* Signal[sample, :] = D
This will fail when sample is ~4. If I change the range to (5,N),
skipping the "bad" file location, it will run fine for a few samples,
and then give another error. The message it gives is:
"16 items requested but only 7 read"
So D is a 7x1 vector, and the program dies when it tries to assign D
to the slice of Signal ("ValueError : shape mismatch: objects cannot be
broadcast to a single shape").
Onwindows, the Python version is 2.5.2, and the most recent numpy and
scipy are being used as well. I tried using Enthought, but it gave
this error as well, in addition to a c runtime error whenever I
imported scipy (which is another post topic...).
Any ideas on what might be causing this? Is there a way to debug the
fromfile function? And, remember, this works perfectly on a Mac. Would
compiling everything (python, scipy, numpy) potentially solve this?
Did you open the file in binary mode ?
Greetings, Uwe

Yes I did. Would that make a difference between a mac andwindows?
Thanks
Uwe,
Thanks for the suggestion. I passed "rb" to the open file command, not
'rb' which made a difference. I thought it opened in binary, but it
did not, and it seems windows is not as good unix for dealing with
this situation.
Adam
Jul 23 '08 #4
jadamwil wrote:
On Jul 22, 2:05 am, Uwe Schmitt <rocksportroc.. .@googlemail.co m>
wrote:
>jadamwil schrieb:
>>Hello,
I am using the numpy fromfile function to read binary data from a file
on disk. The problem is that the program runs fine on a Mac, but gives
an error or warning on windows when trying to read the data. I use it
like this:
Signal = zeros((N, 16), dtype=float32)
for sample in range(0, N):
# this function gets the next position in the file to seek to
s = getFilePos(samp le)
# go to the correct location in the file; this IS checked to make
sure it is within the file
mFile.seek(s)
# read the 16 float32 values from the file
D = fromfile(mFile, dtype=numpy.flo at32, 16)
# save D in Signal
Signal[sample, :] = D
This will fail when sample is ~4. If I change the range to (5,N),
skipping the "bad" file location, it will run fine for a few samples,
and then give another error. The message it gives is:
"16 items requested but only 7 read"
So D is a 7x1 vector, and the program dies when it tries to assign D
to the slice of Signal ("ValueError : shape mismatch: objects cannot be
broadcast to a single shape").
On windows, the Python version is 2.5.2, and the most recent numpy and
scipy are being used as well. I tried using Enthought, but it gave
this error as well, in addition to a c runtime error whenever I
imported scipy (which is another post topic...).
Any ideas on what might be causing this? Is there a way to debug the
fromfile function? And, remember, this works perfectly on a Mac. Would
compiling everything (python, scipy, numpy) potentially solve this?
Did you open the file in binary mode ?

Greetings, Uwe

Yes I did. Would that make a difference between a mac and windows?
Thanks
In a word, yes.
the values for bytes that have issues are 10 and 13.

--Scott David Daniels
Sc***********@A cm.Org
Jul 23 '08 #5
One question : Did you remember to open the file in binary mode?
This MUST be done on windows.
On 22 jul 2008, at 06.36, jadamwil wrote:
Hello,
I am using the numpy fromfile function to read binary data from a file
on disk. The problem is that the program runs fine on a Mac, but gives
an error or warning on windows when trying to read the data. I use it
like this:

Signal = zeros((N, 16), dtype=float32)
for sample in range(0, N):
# this function gets the next position in the file to seek to
s = getFilePos(samp le)

# go to the correct location in the file; this IS checked to make
sure it is within the file
mFile.seek(s)

# read the 16 float32 values from the file
D = fromfile(mFile, dtype=numpy.flo at32, 16)

# save D in Signal
Signal[sample, :] = D

This will fail when sample is ~4. If I change the range to (5,N),
skipping the "bad" file location, it will run fine for a few samples,
and then give another error. The message it gives is:
"16 items requested but only 7 read"

So D is a 7x1 vector, and the program dies when it tries to assign D
to the slice of Signal ("ValueError : shape mismatch: objects cannot be
broadcast to a single shape").

On windows, the Python version is 2.5.2, and the most recent numpy and
scipy are being used as well. I tried using Enthought, but it gave
this error as well, in addition to a c runtime error whenever I
imported scipy (which is another post topic...).

Any ideas on what might be causing this? Is there a way to debug the
fromfile function? And, remember, this works perfectly on a Mac. Would
compiling everything (python, scipy, numpy) potentially solve this?

Thanks!
--
http://mail.python.org/mailman/listinfo/python-list
----------------------------------
Skinheads are so tired of immigration, that they are going to move to
a country that don't accept immigrants!
Tommy Nordgren
to************@ comhem.se

Jul 23 '08 #6
I found the problem: I thought it was opening in binary mode on BOTH
windows and the mac, but on windows I passed "rb" with double quotes,
not 'rb' with single quotes to the open file function. Changing it to
'rb' fixed it.

On Jul 23, 8:25*am, Tommy Nordgren <tommy.nordg... @comhem.sewrote :
One question : Did you remember to open the file in binary mode?
This MUST be done on windows.
On 22 jul 2008, at 06.36, jadamwil wrote:
Hello,
I am using the numpy fromfile function to read binary data from a file
on disk. The problem is that the program runs fine on a Mac, but gives
an error or warning on windows when trying to read the data. I use it
like this:
Signal = zeros((N, 16), dtype=float32)
for sample in range(0, N):
*# this function gets the next position in the file to seek to
*s = getFilePos(samp le)
*# go to the correct location in the file; this IS checked to make
sure it is within the file
*mFile.seek(s)
*# read the 16 float32 values from the file
*D = fromfile(mFile, dtype=numpy.flo at32, 16)
*# save D in Signal
*Signal[sample, :] = D
This will fail when sample is ~4. If I change the range to (5,N),
skipping the "bad" file location, it will run fine for a few samples,
and then give another error. The message it gives is:
"16 items requested but only 7 read"
So D is a 7x1 vector, and the program dies when it tries to assign D
to the slice of Signal ("ValueError : shape mismatch: objects cannot be
broadcast to a single shape").
On windows, the Python version is 2.5.2, and the most recent numpy and
scipy are being used as well. I tried using Enthought, but it gave
this error as well, in addition to a c runtime error whenever I
imported scipy (which is another post topic...).
Any ideas on what might be causing this? Is there a way to debug the
fromfile function? And, remember, this works perfectly on a Mac. Would
compiling everything (python, scipy, numpy) potentially solve this?
Thanks!
--
http://mail.python.org/mailman/listinfo/python-list

----------------------------------
Skinheads are so tired of immigration, that they are going to move to *
a country that don't accept immigrants!
Tommy Nordgren
tommy.nordg...@ comhem.se
Jul 23 '08 #7
Manu Hack wrote:
by the way, anyone could explain why changing to single quote makes a
difference?
>>"rb" == 'rb'
True
There's no difference between single quotes and double quotes in Python.
My guess is cargo cult debugging.

</F>

Jul 23 '08 #8
On Jul 23, 3:30*pm, Fredrik Lundh <fred...@python ware.comwrote:
Manu Hack wrote:
by the way, anyone could explain why changing to single quote makes a
difference?
*>>"rb" == 'rb'
True

There's no difference between single quotes and double quotes in Python.
* * My guess is cargo cult debugging.

</F>
Ha...you're probably not that far from the truth. I just started with
python about a week ago, and have had a LOT of luck getting our lab's
data analysis routines ported from matlab, with the exception of this
problem. I tried a lot of different things to get it working on
windows, and I think I got python quotes confused with matlab or php
quotes (where double and single quotes are different), tried it, and
it happened to work (although I probably changed something else as
well in desperation). Of course, as many have pointed out, this does
not actually matter in python. So anyway, yes, someone new to a
language trying lots of different things without a full understanding
of the language could probably be considered cargo cult
programming :-). Thanks for the replies though!
Jul 23 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
4167
by: bsmalik | last post by:
Hi All, I am trying to do a simple thing. ----------------------------- Dim NCImage As System.Drawing.Image = System.Drawing.Image.FromFile("NC.jpg") ---------------------------- I have the image NC.jpg and its a valid image but the error i get is FileNotFound. Can u plez tell me whats wrong?
2
11965
by: steve | last post by:
imports system.drawing imports system.drawing.image dim img as image = image.fromfile("a.bmp") picturebox1.image = img i'm using vs 2003 and the error i have is that fromfile is not a member of system.drawind.image...what gives?!? tia,
0
3874
by: Taiwo | last post by:
When I use the method "System.Drawing.Image.FromFile(pictureFile)" where pictureFile is the path to a valid image file, the file is locked even minutes after the statement executes. This code is in a web service hosted in IIS on Windows XP. Typically, I have to run IISRESET from the Command Line to be able to rename the file. My work around...
2
6683
by: active | last post by:
I find Bitmap.Save works for WMF files but Bitmap.FromFile does not. If I use FromFile on a WMF file that came with VS I get an exception. If I use it on a WMF file created with Bitmap.Save I don't get an exception but it appears the Bitmap is blank. Can anyone share some knowledge on this?
2
6261
by: PJ | last post by:
Hi I was developing a Class for skinning an application. IN order to read the image file dynamically I used System.Drawing.Image.FromFile("..."). Strangely VS 2003 returns an error saying that "FromFile is not a member of the System.Drawing.Image". According to the member list under IMage class that is not true. I am completely baffled by...
4
3043
by: escristian | last post by:
Hello. I'm trying to create an Image so I use something like this: Image newImage = Image.FromFile(filename); Now when it's a bmp file and certain .gif files it gives me an exception that says: "Invalid parameter used". The gif an bmp files are valid image files, I can open them in any graphics software and windows can do the preview.
1
4217
by: Dana | last post by:
I tried loading an icon to an imageList using the following method: Image cc = Bitmap.FromFile("C:\\myicon.ico"); imageList1.Images.Add(cc); It works with some icons but generates an "Out of Memory" error with some others. The strange thing is that when I try to add the icon manually to the imageList, it adds it without problems!! One...
8
1662
by: =?Utf-8?B?WVhR?= | last post by:
Hello, I used Image.FromFile method to get lots of images from files, it's very slow in Windows Vista, but it's fast in Windows XP! could anyone please tell how to speed in Windows Vista? thank you
0
7547
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7825
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8060
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7588
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6176
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3596
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1159
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
865
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.