Question: 2 ) read binary data ( 2 0 points ) read the binary data generated with the matlab code stored in the file 'data.bin' you

2) read binary data (20 points)
read the binary data generated with the matlab code stored in the file 'data.bin'
you need the following parts
- open the file and assign a file handle
- read the binary data and store the data (output) in binary_data
- close the file
- unpack the data
* set a variable nx =1001
* set a variable nt =500
* compute a variable n which is the product of nx and nt
* set a variable fmt ='d'*(n*3)
* call the struct.unpack function with the inputs fmt and binary_data return the output to data
* reshape the data array using the following function: np.array(data).reshape((nt, nx,3))
- data is now a 3d array of the dimensions(nt,nx,nvars) where nt is the number of time instances, nx is the number of lcoations and nvars is the number of variables (here 3: x, t and p)
- save the data in 3 separate 2d arrays called x,t and p as follows
* x = data[:, :,0]
* t = data[:, :,1]
* p = data[:, :,2]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!