Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Numpy misindentifying data type

I am calculating the coordinates of a H2O using numpy.
I know that am using proper data types in the creation itself.

r = 0.9820
angle_rad = np.deg2rad((180-103.718)/2)
off_x = r*np.cos(angle_rad)
off_y = r*np.sin(angle_rad)

h2o_base = np.array([['O', np.float64(0.), np.float64(0.), np.float64(0.)], 
            ['H', -off_x, off_y, np.float64(0.)],
            ['H',  off_x, off_y, np.float64(0.)]
           ])
h2o_base

I am expecting an array with (string, float, float, foat) data types but when I check it.
the output of this code is

array([['O', '0.0', '0.0', '0.0'],
       ['H', '-0.7723363998864039', '0.606482056956765', '0.0'],
       ['H', '0.7723363998864039', '0.606482056956765', '0.0']],
      dtype='<U32')

Which is full of string elements.
May I ask for some help with this ?
Shouldn’t it automatically detect the proper data type ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Adding the dtype=object specification

h2o_base = np.array([['O', np.float64(0.), np.float64(0.), np.float64(0.)], 
                     ['H', -off_x, off_y, np.float64(0.)],
                     ['H',  off_x, off_y, np.float64(0.)]], 
                    dtype=object)

should make the trick.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading