numpy basics Flashcards

1
Q

import the numpy library

A

import numpy as np

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

in a 2-D array, what are the axes labels for row and column?

A

rows - axis 0

cols - axis 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

in a 3-D array what are the axes numbered as for rows, columns and array?

A

rows - axis 0
cols - axis 1
array - axis 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

create an array in numpy

A

a = np.array([2,3,5])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

create a 2-D array in numpy

A

two_d = np.array([(3,3,6),(1,4,7)])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

create a 3-D array in numpy

A

c = np.array([[(3,4),(1,3)],[(25,2),(1,55)]])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

create an array of zeroes as integers with a length of 5

A

x = np.zeros(5, dtype=int)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

create a 2-d array of zeroes as integers, with dimensions of 5 rows by 3 columns

A

x = np.zeros((5,3),dtype=int)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

create an array of even numbers from 2 -> 46 using numpy

A

a = np.arange(2,47,2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

create an array of 10 evenly spaced values between 0 and 64 inclusive

A

a = np.linspace(0,65,10)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

create a 3 x 5 matrix (3 rows, 5 columns) filled with the number 10

A

a = np.full((3,5),10)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

create an identity matrix measuring 3x3

A

np.eye(3)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

create a 2x8 matrix (row x col) filled with random numbers

A

np.random.random((2,8))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

see row x col dimensions of an array

A

a.shape

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

see if 1-d, 2-d, 3-d, etc of an array

A

a.ndim

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

see data type of an array

A

a.dtype.name

17
Q

convert array to int

A

a = a.astype(int)

18
Q
get square root of an array
get log of an array
get exponentiation of array
get sin of an array
get cos of an array
A
b = np.sqrt(a)
b = np.log(a)
b = np.exp(a)
b = np.sin(a)
b = np.cos(a)
19
Q

get the dot product of transposed matrices

A

a.dot(b)

20
Q
get sum of an array
get min of an array
get max of rows
get cumulative sum
get mean of array
get median
get standard deviation
copy an array
sort an array
A

a.sum()
a.min()
a.max(axis=0)
a.cumsum()
a.mean()
a.median()
np.std(a)
b = a.copy()
a.sort()

21
Q

get correlation coefficient between two arrays

A

np.corrcoef(a,b)

22
Q

transpose and array - what does it mean and how do you do it?

A

diagonal flip of a matrix…
cols => rows
rows = > cols

b = np.transpose(a)

23
Q

flatten a multi-dimensional array

A

a.ravel()

24
Q

reshape an array, but don’t change data

A

a.reshape(2,3)

25
Q

concatenate 2 arrays

A

c = np.concatenate((a,b), axis=0)

26
Q

stack 2-D array (row-wise)

A

c = np.vstack(a,b)

27
Q

stack 2-D array (col-wise)

A

c = np.hstack(a,b)

28
Q

split 2-D array every other row

A

c = np.vsplit(b, n/2) where n == row length

29
Q

split 2-D array horizontally by every other column

A

c = np.hsplit(b, n/2) where n == col length