I have an array of arrays and I'm trying to find the lowest non-zero value among them all.
minima = []
for array in K: #where K is my array of arrays (all floats)
if 0.0 in array:
array.remove(0.0)
minima.append(min(array))
print min(minima)
This yields
AttributeError: 'numpy.ndarray' object has no attribute 'remove'
I thought array.remove()
was the way to remove an element. What am I doing wrong?
What is AttributeError: ‘numpy.ndarray’ object has no attribute ‘append’? In Python, it is common to use the append () method to add an element to the end of the array like we do in the list.
The AttributeError: ‘numpy.ndarray’ object has no attribute ‘append’ occurs if you attempt to append an element into NumPy array using the regular append () method like we do in the list. The numpy.ndarray does not have an append method, and hence it throws AttributeError.
Numpy arrays have no attribute named columns If you want to see what features SelectFromModel kept, you need to substitute X_train (which is a numpy.array) with X which is a pandas.DataFrame. This will return a list of the columns kept by the feature selector.
This error occurs when you attempt to use the index () function on a NumPy array, which does not have an index attribute available to use. The following example shows how to address this error in practice.
I think I've figured it out.
The .remove()
method is a list method, not an ndarray method.
So by using array.tolist()
I can then apply the .remove()
method and get the required result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With