Performant Python

Solutions

In [4]:
# arange for arrays (similar to range for lists)
w = np.arange( -2, 6, 2 )
print(w)
[-2  0  2  4]
In [5]:
# linspace to create regular sample points in an interval
x = np.linspace(-10, 10, 5) 
print(x)
[-10.  -5.   0.   5.  10.]
In [6]:
# Create an array of zeros
y = np.zeros(3)
print(y)
[0. 0. 0.]
In [7]:
#Create an array of ones
z = np.ones(3)
print(z)
[1. 1. 1.]

In [10]:
print("Size       ", a.size)
Size        3
In [11]:
print("Data type  ", a.dtype)
Data type   int64