Python Part 4: Numpy Flashcards
axis = 0 in a 2d array
vertical or horizontal?
vertical
axis = 1
vertical or horizontal for 2d array?
horizontal
create an array with the numbers 1, 2, 3, 4, 5
arr = np.array([1,2,3,4,5])
arr = np.arange(1,6)
create an array of 10 zeros
create an array of ones with the dimensions 3x4
arr1 = np.zeros(10)
arr2 = np.ones((3,4))
create an array with a range of numbers
- create an array with 0,1,2
- create an array with 3,4,5
np.arange(range)
zB
arr1=np.arange(3)
arr2=np.arange(3,6)
np.random.randint(): 4 occurrences
numpy.random.rand():
Create an array of the given shape and populate it with random samples from a uniform distribution over [0, 1).
np.mean(): 4 occurrences
Standard Deviation?
np.std(array)
also
np.std(array, axis = x)
Variance ?
np.var(array)
Array Reshaping ?
arr.reshape(new dimensions)
arr = np.arange(12)
newarr = arr.reshape(4,3)
print(newarr)
arr = np.arange(12)
newarr = arr.reshape(4,3)
print(newarr)
output?
[[ 0 1 2]
[ 3 4 5]
[ 6 7 8]
[ 9 10 11]]
arr1=np.arange(3)
arr2=np.arange(3,6)
output arrays?
[0 1 2]
[3 4 5]
numpy.random.randn():
Generate random numbers from a standard normal distribution
numpy.random.randint():
Generate random integers between specified limits.
numpy.random.shuffle():
Shuffle the elements of an array randomly.
initialise an 1x5 array of random integers smaller than 16
xarr1=np.random.randint(16,size=5)
initialise a 3x3 array of random integers >= 7 and < 12
xarr2=np.random.randint(7,12,size=(3,3))
Initialise a 3x5 array, choosing numbers randomly from the set (3, 5, 7, 9)
x = random.choice([3, 5, 7, 9], size=(3, 5))