简体   繁体   中英

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: 在此处输入图像描述

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)

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

在此处输入图像描述

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'.

在此处输入图像描述

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM