1

I'm trying to write this simple script but for some reason i'm struggling with the mathematical multiply operation. The error that I am getting is

ufunc 'multiply' did not contain a loop with signature matching types dtype('<U32') dtype('<U32') dtype('<U32')

I am using PyCharm for the first time as editor and I've never had this problem with jupiter.

This is my code

import numpy as np


polar_surfacetension = input('Enter the polar component of the surface tension in mN/m (46.4 for water): ')
polar_dispersive = input('Enter the dispersive component of the surface tension in mN/m (26.4 for water): ')
polar_angle = list()
print("Polar Solvent measurements")
num = input("Enter numbers of measurements performed :")
print('Enter angles values in degrees: ')
for i in range(int(num)):
    n = input("Value :")
    polar_angle.append(float(n))

non_polar_surfacetension = input('Enter the  non polar component of the surface tension in mN/m (50 for \
diiodomethane): ')

print("Non Polar Solvent measurements")
non_polar_angle = list()
num_2 = input("Enter numbers of measurements performed :")
print('Enter angles values in degrees: ')
for i in range(int(num_2)):
    n = input("Value :")
    non_polar_angle.append(float(n))

solid_dispersive = (((np.cos([non_polar_angle])+1)**2)*non_polar_surfacetension)/4

print (solid_dispersive)

Thank you!

Mr. T
  • 11,960
  • 10
  • 32
  • 54
xFugtree
  • 45
  • 1
  • 2
  • 12
  • Can you paste the full traceback of your error, as well as the values you used for your input variables that yielded the error? The example you provided does not produce any errors for me. It may be helpful to replace the `input` calls in your example with the actual values that you used when observing the error. – Steve Kern Jun 10 '16 at 15:27
  • 4
    You are trying to multiply strings (' – hpaulj Jun 10 '16 at 15:29
  • @SteveKern this is the complete error Traceback (most recent call last): File "C:/Users/alepe/Desktop/Wonderland/Research/REU -2016/Surface Energy Calculator.py", line 25, in solid_dispersive = (((np.cos([non_polar_angle])+1)**2)*non_polar_surfacetension)/4 TypeError: ufunc 'multiply' did not contain a loop with signature matching types dtype(' – xFugtree Jun 10 '16 at 19:21
  • What is `non_polar_surfacetension`? A string, a number or what? Don't just assume - test its value. – hpaulj Jun 10 '16 at 19:27
  • @hpaulj it is a number – xFugtree Jun 10 '16 at 19:30
  • 1
    Really? I don't see any code that converts the `input` string to a number. – hpaulj Jun 10 '16 at 19:53
  • Oh, this is python3, isn't it? That changes my original assertion of not seeing an error, as I was testing the example with python 2. @hpaulj is correct, `non_polar_surfacetension` is read in by `input` as a unicode and not evaluated to anything other than that. If you want it to be a number, wrap it in a `float` or `int` like you did for your other input values. – Steve Kern Jun 10 '16 at 20:24

0 Answers0