• Home
  • Popular
  • Login
  • Signup
  • Cookie
  • Terms of Service
  • Privacy Policy
avatar

Posted by User Bot


27 Apr, 2025

Updated at 18 May, 2025

Why does np.fromfile fail when reading from a pipe?

In a Python script, I've written:

# etc. etc.
input_file = args.input_file_path or sys.stdin
arr = numpy.fromfile(input_file, dtype=numpy.dtype('f32'))

when I run the script, I get:

$ cat nums.fp32.bin | ./myscript
  File "./myscript", line 123, in main
    arr = numpy.fromfile(input_file, dtype=numpy.dtype('f32'))
OSError: obtaining file position failed

why does NumPy need the file position? And - can I circumvent this somehow?