Tricks in numpy
Tricky actions numpy could provide
import numpy as np
here we have separate RGB channels of an image, concatenate them using np.concatenate
and np.stack
separately
h, w = 224, 224
R = np.random.randint(0, 256, size=(h, w))
G = np.random.randint(0, 256, size=(h, w))
B = np.random.randint(0, 256, size=(h, w))
# your code here #
p
is a 1D array indicating probability of being dog(y=1). let's say all samples are truly dog and we need to create a ground-truth array for loss computation (don't worry :) you don't need to implement loss function here). imagine you can't explicitly use any shape information for this matter.
num_samples = 100
p = np.random.rand(num_samples)
# your code here
salary
is a 2D array denoting salaries of six employees during 100 months. let's say the manager asks you to analyze his/her employees by answering the following questions (np.argmax
, np.max
, np.argwhere
, np.median
and np.percentile
could be helpful :) )
salary = np.random.randint(5, 150, size=(6, 100))
# your code here
# your code here
# your code here
# your code here
salary
is salaries of six employees during a year. implement code for the following parts
salary = np.random.randint(5, 100, size=(6, 12))
# your code here
# your code here
# your code here
# your code here
np.linspace
and check the difference of all two subsequent elements are close to 0.001# your code here
arr
by one in places provided by indices
arr = np.zeros(5)
indices = np.random.randint(0, 5, size=(1000))
# your code here
arr
, select the 4th and 5th axis of last dimension using both numpy indexing and ellipsis and check their value equality using np.all
arr = np.random.rand(10, 10, 10, 10, 10, 8)
# your code here