Python Data Science

Numpy

Numpy is an important Python Library for many Python applications, especially in Data Science applications

Arrays: Like lists in Python, but cooler and faster

Elements: What is inside the arrays

Syntax:
x = np.array([x, y])
x = np.array([[x, y], [z, q]])

Dimensions in arrays: How many things are in the array (enclosed in [ ]’s)

.ndim: Returns the dimension

.shape: Returns how many things that are in the array (axis-1, axis-2 , axis-3 ….. axis-n)

.dtype: Returns the data type of the array AKA how much space it takes up
You can set this when making the array by adding a ‘,’ and the type: dtype = ‘int(something)’
Int32 = 3 bytes, int8 = 1 byte, int(something) is just how many bits it takes up

.itemsize: Returns how many bytes each thing in the array takes up

.nbytes: Returns how many bytes the entire array takes up

np.zeros(x): Makes an array populated by x amount of zeroes (np.empty(x) is the same one)

np.ones(x): Makes an array populated by x amount of ones

np.linspace(x, y, z): Makes an array that is in the range of x to y and has z amount of elements

Math, Random and Statistics

The ‘math’ module:

math.sqrt(x): The square root of the number in the parentheses

math.fabs(x): The absolute value of the number in the parentheses

math.pow(x, y): Puts the y value in the power of x AKA xy

The ‘Random’ module:

random.randint(x, y): Finds a random integer between x and y, but doesn’t include y

random.random(): Finds a random number between 0 and 1, but doesn’t include 1

random.choice([‘thing’, ‘thing2’, ‘thing3’]): Selects a random thing in the list

The ‘Statistics’ module:

Statistics.mean(): will give you the mean of the list in the parenthesis

Statistics.median(): will give you the median of the list

Statistics.mode(): will give you the mode of the list

Statistics.stdev(): will give you the standard deviation of the list AKA how much the other data deviates from the mean

Statistics.variance(): will give you the variance of the list AKA very similar to the standard deviation thing