Ads by ProfitSence
Close

Only size-1 arrays can be converted to python scalars

Last Updated on Wednesday 5th Oct 2022

PythonTypeErrorļ¼šOnly size-1 arrays can be converted to Python scalars

			
					import math
import matplotlib.pyplot as plt
plt.plot(x, y)
r = np.arange(0, 1, 0.01)
T_0 = pow(math.sqrt(1-pow(r,2)),-1)
L_0 = math.sqrt(1-pow(r,2))

			
	

And the error message appears

TypeError: only size-1 arrays can be converted to Python scalars

Change the math package to the numpy package

			
					import numpy as np
...
T_0 = pow(np.sqrt(1-pow(r,2)),-1) #error list
L_0 = np.sqrt(1-pow(r,2)) #error list