2

I'm trying to divide numpy array by numpy float64 type scalar. Following is my code.

pose_q = np.array(pose_q)
expectecd_q = np.array(expectecd_q)

pose_q = np.squeeze(pose_q)
expectecd_q = np.squeeze(expectecd_q)

q1 = expectecd_q / np.linalg.norm(expectecd_q)
q2 = pose_q / np.linalg.norm(pose_q)

d = abs(np.sum(np.multiply(q1, q2)))

However I'm getting the following error pointing towards expectecd_q / np.linalg.norm(expectecd_q)

TypeError: ufunc 'true_divide' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
Mr. Randy Tom
  • 311
  • 5
  • 13

1 Answers1

3

As you didn't provide your data, I created both arrays as:

a = np.array([12.0, 15.2, 19.3])  # Dividend
b = np.array(3.0)                 # Divider (a Numpy scalar)

If you want to divide a by b run just (no surprise) a / b. The result is:

array([4.        , 5.06666667, 6.43333333])

In your case, maybe you should identify what particular values you have as operands.

I looked in the Web for your error message. I found a suggestion that the cause can be that the array in question has text values (not float). It can happen when you read the array from a database. Check dtype of this array. class 'numpy.ndarray' says only that this is a Numpy array. But what is the type of its elements?

Valdi_Bo
  • 30,023
  • 4
  • 23
  • 41