0

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)
6
  • Could the python installation that Jupyter is using have an old version (1.09 or earlier) of Numpy? Commented Dec 4, 2020 at 16:27
  • @KarlKnechtel When I try to check the version of Numpy, the same error pops up "module 'numpy' has no attribute 'version ' ". I used this code np.version.version Commented Dec 4, 2020 at 16:29
  • Share your full code Commented Dec 4, 2020 at 16:31
  • @YeshwinVermaTheProgrammer I added the code above. Commented Dec 4, 2020 at 16:33
  • Try to print np.__version__ to get the numpy version. Commented Dec 4, 2020 at 18:55

1 Answer 1

1

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!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.