February 24, 2020
We can create an array in NumPy like this:
import NumPy as np
np.array([92, 98, 91, 97])
We’re able to transform csv files into arrays using the np.genfromtxt( ) function.
csv_array = np.genfromtxt(‘sample.csv’, delimiter=’,’)
Generally, NumPy arrays are more efficient than lists. One reason is that they allow you to do element-wise operations.
An element-wise operation allows you to quickly perform an operation, such as addition, on each element in an array.
#With a list
L = [1,2,3,4,5]
L_plus_3 = []
for i in range(len(L)):
L_plus_3.append(L[i] + 3)
#With an array
a = np.array(L)
a_plus_3 = a + 3