0

I have this code:

valueXs = [7, 9, 10, 11, 8, 5, 2, 9, 18, 17, 15, 7]
diff = np.diff(np.sign(np.diff(valueXs)))
maxi = np.where(diff < 0)[0]+1

but when I try: valueXs[maxi] I get the error:

TypeError: only integer scalar arrays can be converted to a scalar index
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
  • Try to do `print(maxi)` and you will see the problem. It will also help you to read about [How to debug small programs](http://ericlippert.com/2014/03/05/how-to-debug-small-programs/) – Tomerikoo Sep 23 '20 at 09:48
  • 1
    You seem to be ignoring or unaware of the difference between arrays and lists. You can't index a list with an array. – user2357112 Sep 23 '20 at 09:52
  • Does this answer your question? [Access multiple elements of list knowing their index](https://stackoverflow.com/questions/18272160/access-multiple-elements-of-list-knowing-their-index) – Dishin H Goyani Sep 23 '20 at 10:03

1 Answers1

0
valueXs = np.array([7, 9, 10, 11, 8, 5, 2, 9, 18, 17, 15, 7])
diff = np.diff(np.sign(np.diff(valueXs)))
maxi = np.where(diff < 0)[0]+1
valueXs[maxi]

converted your valueXs to np.array to allow array indexing

Gulzar
  • 23,452
  • 27
  • 113
  • 201