i am trying to import :
from sklearn.cluster import KMeans as sk_KMeans
but i get the following error:
AttributeError: module 'numpy' has no attribute 'float'
how do i fix this?
from sklearn.preprocessing import PowerTransformer
pt = PowerTransformer(method='yeo-johnson',standardize=True)
X_train['feature']=pt.fit_transform(np.array(X_train['feature']).reshape(-1, 1))
#fit the model only on the train set and transform the test set
X_test['feature']=pt.transform(np.array(X_test['feature']).reshape(-1, 1))
getting below error
AttributeError: module 'numpy' has no attribute 'warnings'
working fine with numpy==1.23.4
giving error with numpy==1.24.0
I get the following error with the code import keras:
AttributeError: module 'tensorflow.python.util.dispatch' has no attribute 'add_fallback_dispatch_list'
Hi, I was trying some code from WesMckinney's python data analysis book in ipython environment,which is built in anaconda. When I typed the simple code like
import matplotlib.pyplot as plt
fig = plt.figure
ax1 = fig.add_subplot(2,2,1)
Traceback (most recent call last):
File "<ipython-input-9-559e30a6412a>", line 1, in <module>
ax1 = fig.add_subplot(2,2,1)
AttributeError: 'function' object has no attribute 'add_subplot'
An AttributeError arose, but it's weird since anaconda is surely installed with matplotlib module. So Any suggestion? thank you.
The issue is that you don't have the open and close brackets (()) at the end of plt.figure, so you haven't actually created a figure, just assigned a handle fig to the plt.figure function. Instead, try:
import matplotlib.pyplot as plt
fig = plt.figure() #Here is your error
ax1 = fig.add_subplot(2,2,1)
I am using numpy and matplotlib in Python3.
The following code is causing the error:
import matplotlib
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib.axes import Subplot as plt
from matplotlib import pylab
a=[1,1]
b=[1,1]
fsam = 48000
w, h = freqz(b, a, worN=2000)
plt.plot(((fsam-8000) * 0.5 / np.pi) * w, abs(h), label=" ")
The actual error with matplotlib 1.3.x:
File "/usr/local/lib/python3.2/dist-packages/matplotlib-1.3.x-py3.2-linux-x86_64.egg/matplotlib/axes.py", line 4119, in plot
if not self._hold:
AttributeError: 'numpy.ndarray' object has no attribute '_hold'
The actual error with matplotlib 1.2.0:
Traceback (most recent call last):
File "/home/christoph/audio_measurement/AudioTools/AudioTools.py", line 222, in <module>
main()
File "/home/christoph/audio_measurement/AudioTools/AudioTools.py", line 216, in main
form = AppForm()
File "/home/christoph/audio_measurement/AudioTools/AudioTools.py", line 39, in __init__
self.on_draw()
File "/home/christoph/audio_measurement/AudioTools/AudioTools.py", line 80, in on_draw
self.transfer = Transfer(self.canvas)
File "/home/christoph/audio_measurement/AudioTools/Transfer.py", line 42, in __init__
plt.plot(((fsam-8000) * 0.5 / np.pi) * w, abs(h), label=" ")
File "/usr/local/lib/python3.2/dist-packages/matplotlib/axes.py", line 3995, in plot
if not self._hold: self.cla()
AttributeError: 'numpy.ndarray' object has no attribute '_hold'
Transfer is the class, which plots onto the canvas.
I had a look at the length of the coefficients a and b, but they did not effect the result.
I could not find anything on that. Does anyone know whats going wrong?
Normally I'd use import matplotlib.pyplot as plt with plt.plot, plt.subplot, plt.show, etc -- or even just from pylab import *. Anyway, this line
from matplotlib.axes import Subplot as plt
is the reason you have an unbound plot function that's trying to operate on the ndarray argument. Subplot needs to be instantiated. This should work:
import numpy as np
from scipy.signal import freqz
import matplotlib
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib.axes import Subplot
fig = Figure()
ax = Subplot(fig, 111)
fig.add_subplot(ax)
canvas = FigureCanvas(fig)
a=[1,1]
b=[1,1]
fsam = 48000
w, h = freqz(b, a, worN=2000)
ax.plot(((fsam-8000) * 0.5 / np.pi) * w, abs(h), label=" ")
canvas.show()