Python Forum
loading a 3D array from a bin file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
loading a 3D array from a bin file
#1
Hello Python forum

I am trying to load a 3D array from a bin file. However, when I load it is displayed as a long vector instead.

data=np.fromfile("turbine32x32x8192.bin",dtype=float, sep='')
data.shape
>> (4194304,)
where it should have the shape
data.shape
(32,32,8192)
What I am doing wrong ?

Thank you for reading!

BR Mark

Hello again Python Forum
I figured out a solution to the problem (Or rather I got help from an instructor)

import numpy as np
data=np.fromfile("turbine32x32x8192.bin",dtype=np.float32, sep='')
then the array becomes
Output:
data.shape >>(8388608,0)
Finally I can reshape the file the my desired array
data=data.reshape(32,32,8192)
Output:
data.shape >>(32,32,8192)
Reply
#2
Thanks for posting the solution, glad you got it working :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  JSON file Loading issue punna111 4 8,491 Jun-29-2020, 08:07 AM
Last Post: buran
  Read file Into array with just $0d as Newline lastyle 5 3,310 Feb-03-2020, 11:58 PM
Last Post: lastyle
  memory issue loading movie to numpy array djf123 1 2,247 Nov-07-2019, 06:19 AM
Last Post: ThomasL
  loading a csv file into python from pandas. Variable is not recognized vijjumodi 2 2,877 Apr-19-2019, 04:09 AM
Last Post: kus
  save 2d array to file and load back ian 3 18,157 May-18-2018, 05:00 AM
Last Post: scidam
  access a very large file? As an array or as a dataframe? Angelika 5 4,859 May-18-2017, 08:15 AM
Last Post: Angelika

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020