reading-notes

Software Development Reading Notes

View on GitHub

JupyterLAb

NumPy

Creating A NumPy Array

# by import files

import csv
with open("winequality-red.csv", 'r') as f:
    wines = list(csv.reader(f, delimiter=";"))
import numpy as np
wines = np.array(wines[1:], dtype=np.float)
import numpy as np
empty_array = np.zeros((3,4))
empty_array

Using NumPy To Read In Files

wines = np.genfromtxt("winequality-red.csv", delimiter=";", skip_header=1)

Slicing NumPy Arrays

using a colon (:). A colon indicates that we want to select all the elements from the starting index up to but not including the ending index.

wines[:3,3]
array([ 1.9, 2.6, 2.3])

N-Dimensional NumPy Arrays

earnings = [
    [
        [500,505,490],
        [810,450,678],
        [234,897,430],
        [560,1023,640]
    ],
    [
        [600,605,490],
        [345,900,1000],
        [780,730,710],
        [670,540,324]
    ]
]

NumPy Array Operations

ny of the basic mathematical operations (/, *, -, +, ^) with an array and a value, it will apply the operation to each of the elements in the array.

Broadcasting

Free NumPy Cheat Sheet

Numpy Cheat Sheet Download here!