Why do I get “ufunc ‘multiply’ did not contain a loop with signature matching types dtype(‘S32’) dtype(‘S32’) dtype(‘S32’)” with values from raw_input

From the documentation of raw_input:

The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that.

So what happens is that you try to multiply a string with a float, something like y="3" * x - 0.5 * "3" *x**2, which is not defined.

The easiest way to circumvent this is to cast the input string to float first.

x = np.linspace(0., 9., 10)
a = float(raw_input('Acceleration ='))
v = float(raw_input('Velocity = '))
y = v * x - 0.5 * a * x**2

Mind that if you’re using Python 3, you’d need to use input instead of raw_input,

a = float(input('Acceleration ='))

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)