-1

I don't have any idea with this error,

import NumPy as np

X = np.array([[1,2,3],
              [4,5,100],
              [-1,2,100],
              [3,8,9232020]])
print(X)
print('\n Dimension of the array is:')
print(X.shape)

def getMax(X):
  this_max=X[0]
  for e in X:
    if e > this_max:
      this_max=e
  return this_max

x_max=getMax(X)
print('x_max',x_max)
print('x_max', np.max(X))

the error is "if e > this_max:", and it is telling me the truth value of an array with more than one element is ambiguous. Use a.any() or a.all(), I don't know how to fix it.

Paul Rooney
  • 20,879
  • 9
  • 40
  • 61
Bai
  • 33
  • 4

2 Answers2

0

Each e represents a list in X, for example X[0] = [1,2,3]. I assume you want to iterate over each list in the array to find the max value of all lists in the array.

0

In your code this_max is an array and e is an array (X is 2-dim). I suggest you try:

def getMax(X):
  this_max=X[0][0]
  for x in X:
    for e in x:
      if e > this_max:
        this_max=e
  return this_max
Timus
  • 10,974
  • 5
  • 14
  • 28