# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
import numpy as np
import math
#task 2e
x = np.linspace(-0.0001,0.1,50)
#constants
e0=8.85*10 ** (-12)
Use numpy.sqrt rather than math.sqrt
. numpy.sqrt
expects a scalar or array as input, on the other hand math.sqrt
can only handle scalars.
>>> import numpy as np
>>> import math
>>> a = np.arange(5)
>>> np.sqrt(a)
array([ 0. , 1. , 1.41421356, 1.73205081, 2. ])
#error
>>> math.sqrt(a)
Traceback (most recent call last):
File "", line 1, in
math.sqrt(a)
TypeError: only length-1 arrays can be converted to Python scalars
>>>