I am implementing unscented kalman filter and getting this error "numpy.ndarray object is not callable" for the non-linear function 'g' in the prediction step.
enter image description here
I have also attached my code where I got this error. Any assistance would be highly appreciated. Thanks!
Just like the error message says, gx is a numpy array:
gx = np.array([g_E, g_R])
But you are trying to call it as if it were a function:
self.sigmas_x[:,i] = gx(self.sigmas[:,i],dt, u)
Hence the error.
Related
I am trying to use scipy.optimize spo, and keep on getting error " 'numpy.float64' object is not callable". Could anyone point me to where the error is coming from? TIA!
The first argument of scipy.optimize.minimize is a call able, and you seem to give it a function value instead. In the OP screenshot, what is -sharpe_ratio.
You might be looking for lambda x, prices_norm : -sharpe_ratio(x, prices_norm) or some such.
I am currently trying to display an image in tkinter and identify its body using mediapipe. I use Opencv, mediapipe and tkinter for this. I have also implemented something for this, but unfortunately I am not getting anywhere.
The type of the first argument of mpDraw.draw_landmarks should be NumPy array, but you are passing and object of type PhotoImage.
You may replace landmarks(photo, results) with:
landmarks(image, results)
The following code:
photo = ImageTk.PhotoImage(image=Image.fromarray(image))
landmarks(photo, results)
Converts image from NumPy array to PhotoImage object, and passes the object as argument to landmarks method (that passes it to mpDraw.draw_landmarks).
Take a look at the error message:
if image.shape[2] != RGB_CHANNELS:
AttributeError: 'PhotoImage' object has no attribute 'shape'
That means the image type is 'PhotoImage'.
That also implies that image must have a 'shape' attribute, and we some experience we know that NumPy arrays have a 'shape' attribute.
You may also look at drawing_utils.py.
Args:
image: A three channel RGB image represented as numpy ndarray.
Note:
It's hard to tell if there are other errors (it's hard to follow the code).
My answer address only the posted error messgae.
I am dealing with error
"AttributeError: 'numpy.ndarray' object has no attribute 'nipy_spectral'"
while running silhouette analysis.
The original code was taken from here. I have added the line that shows the error:
color = cm.nipy_spectral(float(i) / n_clusters)
The problem was that you were assigning cm to some other array. Correct way is not to assign cm to any other array or change the code to
matplotlib.cm.nipy_spectral(float(i) / n_clusters)
Change it at all the places where cm is used.
Here is the snippet of the input data and the result of running print(type(cm)).
Screenshot
I am trying to work with LightGBM package in Python and encountered this error:
"TypeError: Wrong type(ndarray) for label, should be list or numpy array".
My target(label) is created as: y_train.values and is an array which has characteristics like:
Type: int64,
Size: (1000,1)
Value: array([[0],
[0],
...)
When I traced back this error,I found this code #
Basic.py code of lightgbm package:
Function list_to_1d_numpy is throwing this error.
I couldn't find any reason though why this function should throw error. However
it is calling one function is_numpy_1d_array which checks for condition
len(data.shape) == 1, however when i do len(y_train.shape) it says 2.
Any ideas how can I resolve it?
Ok, I was thinking in right direction. The label(y_train) needs to be a one dimensional array. I changed it to one dimensional by using:
y=y_train.ravel()
and it worked!
However while creating the target itself, we could have had
y_train=dataframe['target'].values
I had it like: dataframe[['target']].values,
which created 2 dimensional arrays
So I have been writing a code to standardize the elements of a matrix and the function I used is as follows:
def preprocess(Data):
if stdn ==True:
st=np.empty((Data.shape[0],Data.shape[1]))
for i in xrange(0,Data.shape[0]):
st[i,0]=Data[i,0]
for i in xrange(1,Data.shape[1]):
st[:,i]=((Data[:,i]-np.min(Data[:,i]))/(np.ptp(Data[:,i])))
np.random.shuffle(st)
return st
else:
return Data
It works very well outside the class but when used inside of it it gives me this error:
AttributeError: 'tuple' object has no attribute 'shape'
Any idea on how I can fix it??
P.S. This is a KNN classification code
According to the error you posted, Data is of type tuple and there is no attribute shape defined for data. You could try casting Data when you call your preprocess function, e.g.:
preprocess(numpy.array(Data))