Note that there are some explanatory texts on larger screens.

plurals
  1. POValue Error :Storing data from binary file into numpy 3d arrays
    primarykey
    data
    text
    <p>I am trying to read float numbers from a Binary file using Struct module and then storing them in numpy 3D arrays.When I run it as an independent script, it works fine.But when I call it as a class's function from another script(after import) it gives value error Here is my code.</p> <pre><code>import struct from numpy import * class DCD_read: def read_cord(self,total_atoms,dcd_data): cord_data=dcd_data[276:len(dcd_data)] ## binary data string byte=0 count=0 total_frames=info_dict['nset'] coord=numpy.zeros((total_frames,total_atoms,3)) ## 3d array for frames in range(0,total_frames): for atoms in range(0,total_atoms): x = list(struct.unpack('&lt;f',cord_data[60+byte:64+byte])) ###reading float byte+=4 y = list(struct.unpack('&lt;f',cord_data[60+byte:64+byte])) byte+=4 z = list(struct.unpack('&lt;f',cord_data[60+byte:64+byte])) byte+=4 ls=x ls.extend(y) ls.extend(z) coord[frames][atoms]=ls return coord </code></pre> <p>Error:</p> <pre><code>Traceback (most recent call last): File "C:\Users\Hira\Documents\PROJECT\md.py", line 24, in &lt;module&gt; coord=dcd.read_cord(total_atoms,dcd_data) File "C:\Users\Hira\Documents\PROJECT\DCD_read.py", line 51, in read_cord coord=numpy.zeros((total_frames,total_atoms,3)) File "C:\Python27\numpy\core\numeric.py", line 148, in ones a = empty(shape, dtype, order) ValueError: negative dimensions are not allowed </code></pre> <p>md.py is the main (calling script) while DCD_read.py is module. Here is code for md.py (main script)</p> <pre><code>from DCD_read import * import numpy dcd_file=open('frame3.dcd',"rb") dcd_data=dcd_file.read() dcd=read_dcd() total_atoms=6141 coord=dcd.read_cord(total_atoms,dcd_data) </code></pre> <p>Please can any one help???? I hope I explained it completely and clearly.Thanx</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload