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(sample)
# 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.float32, 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! 8 1933
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(sample)
# 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.float32, 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
On Jul 22, 2:05*am, Uwe Schmitt <rocksportroc...@googlemail.com>
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(sample)
* # 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.float32, 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
On Jul 22, 8:35*am, jadamwil <jadamwils...@gmail.comwrote:
On Jul 22, 2:05*am, Uwe Schmitt <rocksportroc...@googlemail.com>
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(sample)
* # 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.float32, 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
jadamwil wrote:
On Jul 22, 2:05 am, Uwe Schmitt <rocksportroc...@googlemail.com>
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(sample) # 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.float32, 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***********@Acm.Org
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(sample)
# 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.float32, 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
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(sample)
*# 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.float32, 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
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>
On Jul 23, 3:30*pm, Fredrik Lundh <fred...@pythonware.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! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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,...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| | |