user11847849
user11847849

Reputation:

Numpy throws a error : AttributeError: module 'numpy' has no attribute 'loadtxt '?

I'm trying to use the np.loadtxt from Numpy in jupyter notebook. But I'm getting this error : enter image description here

This error pops up only in the jupyter notebook. In any other editor, NumPy works fine. Someone have any idea how to resolve this issue?

import numpy as np
# proper dihedrals
pd_i, pd_j, pd_k, pd_l, phi_0, k_phi, mult = np.loadtxt('dihedrals_proper.dat', unpack=True)
pdih = np.vstack((pd_i, 
                  pd_j,
                  pd_k,
                  pd_l)).T


# improper dihedrals
id_i, id_j, id_k, id_l, xsi_0, k_xsi = np.loadtxt('dihedrals_improper.dat', unpack=True)
idih = np.vstack((id_i, 
                  id_j,
                  id_k,
                  id_l)).T


# lennard jones and charges
charges, sigma_i, epsilon_i = np.loadtxt('non_bonded.dat', usecols=(1,2,3), unpack=True)

Upvotes: 0

Views: 1019

Answers (1)

Jiangyan Yang
Jiangyan Yang

Reputation: 36

I met the similar problem today. I also use Jupyter notebook.

enter image description here

In my case, the message "'int' object has no attribute 'array'" means that the object which I supposed it to be the label of numpy, normally 'np', is actually an integer.

Then I found that I created an integer in the code script with the label 'np'.

enter image description here

After I changed the label of the integer, the problem was fixed.

Therefore, I highly recommend you to have a search in your code to see if you have defined a module with the label 'np'.

I hope this answer helps.

Cheers!


The following words is added 1 day after I answered the question. ......

I found the problem in your code is actually not the same with mine.

I think in your case, you need to update your 'numpy' package. As the module has no attribute 'loadtxt'.

It is not the problem of your code script, it is the problem of the package installed in your python.

Cheers!

Upvotes: 1

Related Questions