Skip to content
Advertisement

What am I doing wrong to calculate V from numpy array? I can not get array with “V” values

JavaScript

#ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Advertisement

Answer

The issues are the following:

  • You are comparing an array instead of a value in a condition, which is ambiguous.
    Try 0 < value < a instead 0 < x < a

    To give an example of what you are doing:

    1. You are first assigning the x like [0, 0.1, 0.2, 0.3 ... ]
    2. Then you are comparing 0 < [0, 0.1, 0.2, 0.3 ... ] < 3.9 at line 0 < x < a
  • Also, the variable P is not defined. You will need to provide a value of P like the ones you provide for a and L.

  • To get an array of V values, you will need to push the calculated V values in an empty array or you can use the map function.

A working example:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement