import glob
from os.path import join
import yt
from yt.config import ytcfg
path = ytcfg.get("yt", "test_data_dir")
from mpl_toolkits.mplot3d import Axes3D
my_fns = glob.glob(join(path, "Orbit", "puredef_hdf5_chk_000000"))
my_fns.sort()
fields = ["particle_velocity_x", "particle_velocity_y", "particle_velocity_z"]
ds = yt.load(my_fns[:])
dd = ds.all_data()
indices = dd["particle_index"].astype("int")
print (indices)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-27-1bae40a7b7ba> in <module>
1 ds = yt.load(my_fns[:])
----> 2 dd = ds.all_data()
3 indices = dd["particle_index"].astype("int")
4 print (indices)
AttributeError: 'DatasetSeries' object has no attribute 'all_data'
I have looked at other posts on here, but many of them deal with different aspects of this error that deals with lens or other statements.
I had exactly the same error recently, with a very similar code. First of all, a mistake I did was giving the code the symbolic links to the real data files, while it should work directly with the data.
Another issue was a problem with the installation of the yt library, version 3.6.1. I had installed it using the pip command, but it wasn't working well, so I uninstalled it and I used the "all-in-one" script they provide on their homepage.
Fixing these two things together solved completely this problem.
Related
I'm learning how to use qiskit and I'm using the jupyter notebook, but everytime I try to visualize the circuit with the attribute draw I get this error:
import qiskit
from qiskit import *
from qiskit import IBMQ
qr = QuantumRegister(2)
cr = ClassicalRegister(2)
circuit = QuantumCircuit(qr, cr)
%matplotlib inline
circuit.draw(output='mpl')
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-8-bd220039ee1c> in <module>
----> 1 circuit.draw(output='mpl')
AttributeError: module 'qiskit.circuit' has no attribute 'draw'
I also try applying a Hadamard gate and I get:
circuit.h(qr(0))
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-59-c8b4318b743b> in <module>
----> 1 circuit.h(qr(0))
AttributeError: module 'qiskit.circuit' has no attribute 'h'
It seems that there is a name conflict. It is taking the circuit in from qiskit import circuit instead of circuit = ....
You just probably need to restat your notebook kernel.
Try another name for your circuit variable, right now python thinks you want the qiskit.circuit module to draw something. QuantumCircuit objects are the ones that have a draw method. You can see these two objects here if you call both, note I put one qubit and classical bit in the QuantumCircuit just per example as well you do not need the dots here it is just to make it more clear, just running circuit and QuantumCircuit(1,1) respectively would yield the same result.
You would get desired results if you tried a different variable name:
When I try using the variable name circuit it works for me, but try to use descriptive variable names that also could never be confused with modules or classes from the packages you import.
Also all your import statements can be combined into 1:
from qiskit import *
The star lets you import everything from qiskit including IBMQ. It can help you save a line or two.
I am trying to make an recommender system using SVD python package. I am importing csv file then doing the below operation, but it is showing error. How to solve this?
from surprise import SVD,Reader,Dataset
ratings = pd.read_csv("/content/ratings_small.csv")
data = Dataset.load_from_df(ratings[['userId','movieId','rating']],reader)
data.split(n_folds=5)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-29-f3bf344cf3e2> in <module>()
----> 1 data.split(n_folds=5)
AttributeError: 'DatasetAutoFolds' object has no attribute 'split'
It says it has not split attribute buti went through a question where they have used it.
You need to import KFold from model_selection to split the data and perform cross validation.
This works.
from surprise import SVD,Reader,Dataset
from surprise.model_selection import KFold
ratings = pd.read_csv("/content/ratings_small.csv")
data = Dataset.load_from_df(ratings[['userId','movieId','rating']],reader)
kf = KFold(n_splits=5)
kf.split(data)
Firstly, apologies if this is a silly question, this is my first time using plotly. I am trying to make a sunburst diagram using my 'actor' dataframe, but I get an attribute error when I attempt to do so:
Error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-32-2e5f13ef3c16> in <module>
----> 1 px.data.actor
AttributeError: module 'plotly.express.data' has no attribute 'actor'
Screenshot:
I have the following packages imported at the top:
import plotly.graph_objects as go
import plotly.io as pio
import plotly.express as px
Can anyone see where I'm going wrong? Thanks in advance!
It seems you're assuming that px.data.actor somehow would make your dataframe actor available to plotly. And I can understand why since px.data will make some built-in datasets available to you, like px.data.carshare():
centroid_lat centroid_lon car_hours peak_hour
0 45.471549 -73.588684 1772.750000 2
1 45.543865 -73.562456 986.333333 23
2 45.487640 -73.642767 354.750000 20
3 45.522870 -73.595677 560.166667 23
4 45.453971 -73.738946 2836.666667 19
[...]
244 45.547171 -73.556258 951.416667 3
245 45.546482 -73.574939 795.416667 2
246 45.495523 -73.627725 425.750000 8
247 45.521199 -73.581789 1044.833333 17
248 45.532564 -73.567535 694.916667 5
To inspect all datatasets avaiable to you in the same manner, just run dir(px.data) to get:
['absolute_import',
'carshare',
'election',
'election_geojson',
'gapminder',
'iris',
'tips',
'wind']
But since actor already is available to you (because you've presumably made it yourself), the line px.data.actor() is not necessary at all.
P.S
Running px.express.carshare() returns a pandas dataframe. To keep working with this dataframe it's best to assign it to a variable like this: df_cs = px.data.carshare()
The error looks self-explanatory. I'm not really sure why calling the .actor() method is necessary in the code. px.data will load some datasets that are a part of the library. Some of these include iris, tips, wind, ... Since you already have the dataframe, this call is unnecessary.
Here is an exhaustive list from the code.
Simply remove the line and it should work.
import sklearn
Maybe I'm not understanding something fundamental here, and I just don't know what that may be. How should I go about debugging this?
messages_tfidf = tfidf_transformer.transform(messages_bow)
print messages_tfidf
That part works fine, as intended. But I run into trouble when I test my understanding of .head()
print messages_tfidf.head()
Outputs the error
AttributeError Traceback (most recent call last)
1 messages_tfidf = tfidf_transformer.transform(messages_bow)
2 print messages_tfidf
----> 3 print messages_tfidf.head()
AttributeError: head not found
Can someone help me understand my logical gap here?
Head is a function of pandas DataFrame.
You can do something like that:
import pandas as pd
dframe = pd.DataFrame(messages_tfidf)
dframe.head()
sklearn always works internally with numpy and returns numpy arrays. There is no head function for a numpy array.
I'm trying to generate a random.gauss numbers but I have message error. Here is my code:
import sys,os
import numpy as np
from random import gauss
previous_value1=1018.163072765074389
previous_value2=0.004264112033664
alea_var_n=random.gauss(1,2)
alea_var_tau=random.gauss(1,2)
new_var_n= previous_value1*(1.0+alea_var_n)
new_var_tau=previous_value2*(1.0+alea_var_tau)
print 'new_var_n',new_var_n
print 'new_var_tau',new_var_tau
I got this error:
Traceback (most recent call last):
File "lolo.py", line 15, in <module>
alea_var_n=random.gauss(1,2)
AttributeError: 'builtin_function_or_method' object has no attribute 'gauss'
Someone know what's wrong, I'm a newbye with python. Or is it a numpy version problem.
For a faster option, see Benjamin Bannier's solution (which I gave a +1 to). Your present code that you posted will not work for the following reason: your import statement
from random import gauss
adds gauss to your namespace but not random. You need to do this instead:
alea_var_n = gauss(1, 2)
The error in your post, however, is not the error you should get when you run the code that you have posted above. Instead, you will get the following error:
NameError: name 'random' is not defined
Are you sure you have posted the code that generated that error? Or have you somehow included the wrong error in your post?
Justin Barber shows you an immediate solution for your problem.
Since you are using NumPy you could however use their generators as well since they appear to be significantly faster (about a factor 5-7 on my machine), e.g.
alea_var_n = np.random.normal(1, 2)