Skip to content

a[::-1].tofile(f) creates junk (Trac #436) #1034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
numpy-gitbot opened this issue Oct 19, 2012 · 4 comments
Closed

a[::-1].tofile(f) creates junk (Trac #436) #1034

numpy-gitbot opened this issue Oct 19, 2012 · 4 comments

Comments

@numpy-gitbot
Copy link

Original ticket http://projects.scipy.org/numpy/ticket/436 on 2007-01-27 by @sebhaase, assigned to unknown.

Hi!

arr.tofile(f) creates garbage in f.
f in my case is an open file object at position 1024
(that's the length of our file format's header)

N.__version__
'1.0.1'

It cannot determine what exactly goes wrong - the file size seems to be varying even if arr always has the same size (my arr has dtype=uint16)

Thanks,
Sebastian Haase

@numpy-gitbot
Copy link
Author

@stefanv wrote on 2007-01-27

What do you you get when you run the following code snippet?

import numpy as N

x = N.arange(16).astype(N.uint16)

f = file('test.dat','wb')
hdr = 'x'*1024
f.write(hdr)
x[::-1].tofile(f)
f.close()

f = file('test.dat')
f.seek(1024)
x_ = N.fromfile(f,N.uint16)

print x[::-1]
print x_

I see

[15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0]
[15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0]

with r3511.

@numpy-gitbot
Copy link
Author

@teoliphant wrote on 2007-01-30

I cannot reproduce a problem, either.

@numpy-gitbot
Copy link
Author

@alberts wrote on 2007-02-01

What operating system are you running on? I remember some issues with files on Windows a long time ago. See ticket #701.

@numpy-gitbot
Copy link
Author

@sebhaase wrote on 2007-02-01

Please close this ticket again.

Yes, it was indeed on Windows. Thanks the last comment from albertstrasheim I read the ticket #701 and noticed the importance of binaray mode ('b') on windows !!
I'm very sorry for the noise.

  • Sebastian.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant