0

i defined a formula and i want to have existing array data as input for this function and return results in an array .

the code

x1=np.array(x1)#     <---- existing input data

x_test=[0,5,10,15]    <---- just some test data
x_test=np.array(x_test)

def P_0(x):    
    return 295*(math.cos((0.9952*x+2.25952)*math.pi/180))**2-(295*(math.cos((0.9952*x+1.74)*math.pi/180))**2) 
results=P_0(x_test)

i get error:

TypeError: Required argument 'shape' (pos 1) not found
1
  • math. functions are for scalars, though they might work with a single element array. Commented Sep 20, 2017 at 21:21

1 Answer 1

1

Try changing:

def P_0(x):    
    return 295*(np.cos((0.9952*x+2.25952)*np.pi/180))**2-(295*(np.cos((0.9952*x+1.74)*np.pi/180))**2) 

I have just replaced math.pi to np.pi , math.sin to np.sin and math.cos to np.cos

It's always better if you use functions from numpy while doing operations of numpy arrays

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

1 Comment

@kevin yes mostly.

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.