1

I have initialized an array in the form of

for x in range(0,21000): 
    if np.amax(probability[x]) > 0.2:
        i = i+1

Label = np.zeros(shape=(i,130))

and now with the following for cycle I would like to assign the value to each row of Label

for x in range(0,21000):
    if np.amax(probability[x]) > 0.2:
        Label[i] = [feature[x],y[x],np.amax(probability)[x]]
    i = i+1

Where feature is an array 128*21000. Unfortunately, I keep receving the following error:

Label[i] = [feature[x],y[x],np.amax(probability)[x]]
IndexError: invalid index to scalar variable.
10
  • 1
    You probably want to provide the axis value for the np.amax call otherwise it returns a scalar: docs.scipy.org/doc/numpy-1.14.0/reference/generated/… Commented May 16, 2018 at 13:48
  • This isn't coming from the assignment, but from np.amax(probability)[x], where you're trying to index a scalar. When in doubt about something try each expression individually and see what you get. Commented May 16, 2018 at 13:50
  • Sorry there was a typo, i will fix the question Commented May 16, 2018 at 13:50
  • 1
    Please don't change your question mid-stream. Earlier you were asking about a different error. Commented May 16, 2018 at 13:53
  • Okey, sorry I dind't know that. Can I ask another question ? Commented May 16, 2018 at 13:54

1 Answer 1

1

You don't want a single scalar value for np.amax but rather an array of values. Therefore you need to specify a specific axis for the call as follows:

np.amax(probability, axis=1)

You can see examples of the use of the axis argument from the docs

Or if you really do want to use the scalar value, don't index it using [x] in np.amax(probability)[x]

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

Comments

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.