Reputation: 4050
I am using a softmax function in getting an output from a neural network and getting the minimum value as the output in calculating the error.
However if the output is all the same assuming [0,0,0] the output of the softmax function is [0.33,0.33,0.33]
So when selecting the minimum from this like,
output = softmax(np.dot(hs,HO))
tarminout = np.subtract(target,output)
mine = min(tarminout)
mine = 0.5 * np.power(mine,2)
finalError += mine
It gives the following error because there are more than one equal minimum values,
Traceback (most recent call last):
File "ann.py", line 234, in modulelearn()
File "ann.py", line 97, in learnmine = min(tarminout)
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
How can I get pass this when there are more than 1 equal minimum values by selecting just one of them?
Thanks
Upvotes: 2
Views: 5275
Reputation: 964
The answer's buried in the comments above: your error is likely the result of passing a multi-dimensional ndarray to the standard python min(), which doesn't understand them.
Way #1: call np.min instead of min
Way #2 (not recommended): flatten your array, min(tarminout.ravel())
Way #1 is preferred, use numpy operators on numpy arrays
Upvotes: 2