February 24, 2020

  1. We can create an array in NumPy like this:

    1. import NumPy as np

    2. np.array([92, 98, 91, 97])

  2. We’re able to transform csv files into arrays using the np.genfromtxt( ) function.

    1. csv_array = np.genfromtxt(‘sample.csv’, delimiter=’,’)

  3. Generally, NumPy arrays are more efficient than lists. One reason is that they allow you to do element-wise operations.

  4. An element-wise operation allows you to quickly perform an operation, such as addition, on each element in an array.

    1. #With a list

      1. L = [1,2,3,4,5]

      2. L_plus_3 = []

      3. for i in range(len(L)):

        1. L_plus_3.append(L[i] + 3)

    2. #With an array

      1. a = np.array(L)

      2. a_plus_3 = a + 3

Previous
Previous

March 7, 2020

Next
Next

February 16, 2020