1

I was trying to get the minimum value between tr_loss and val_loss using numpy.min.

np.min(np.min(tr_loss), np.min(val_loss))

The tr_loss and val_loss are numpy arrays that returned from model.fit in keras.

'tr_loss': [0.84579472304284575, 0.77913203762769701, 0.76625978895127778, 0.75814685845822094, 0.75486504282504319, 0.74989902700781819, 0.74833822523653504, 0.74695981823652979, 0.74483485338091848, 0.74150521695762872]

'val_loss': [0.76307238261103627, 0.75163262798049202, 0.74257619685517573, 0.75038179922993964, 0.72936564083517463, 0.73233943380595634, 0.72518632964207708, 0.74037907492741795, 0.7237680551772061, 0.73257833277079065]}

But I keep getting this error

TypeError                                 Traceback (most recent call last)
<ipython-input-35-e82cb24a3b5d> in <module>()
      3 
      4 
----> 5 y_ax_min = np.min(np.min(tr_loss), np.min(val_loss)) - .1
      6 y_ax_max = np.max(np.max(tr_loss), np.max(val_loss)) + .1
      7 plt.figure(figsize=(8, 8),dpi=500)

D:\Anaconda\envs\py27\lib\site-packages\numpy\core\fromnumeric.pyc in 
amin(a, axis, out, keepdims)
   2347             pass
   2348         else:
-> 2349             return amin(axis=axis, out=out, **kwargs)
   2350 
   2351     return _methods._amin(a, axis=axis,

D:\Anaconda\envs\py27\lib\site-packages\numpy\core\_methods.pyc in _amin(a, 
axis, out, keepdims)
     27 
     28 def _amin(a, axis=None, out=None, keepdims=False):
---> 29     return umr_minimum(a, axis, None, out, keepdims)
     30 
     31 def _sum(a, axis=None, dtype=None, out=None, keepdims=False):

TypeError: 'numpy.float64' object cannot be interpreted as an index

Does anyone know where is the problem?

2
  • 3
    Start by reading help(numpy.min). You aren't calling it as intended. The second argument should be an axis. It's not like the built in min function. Commented Apr 14, 2017 at 20:16
  • 2
    When comparing two elements, numpy.minimum should be used instead of numpy.min. @ChrisP Thanks. Commented Apr 14, 2017 at 20:34

1 Answer 1

3

When comparing two elements, numpy.minimum should be used instead of numpy.min.

The comments on this question helped me. Thanks to all those who commented.

Sign up to request clarification or add additional context in comments.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.