Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / Write function to create an n by d np

Write function to create an n by d np

Computer Science

Write function to create an n by d np.ndarray of an integer type with numbers from 0 to k (exclusive) filled in. The numbers should be aranged in order and along the rows. For example, with k=100, n=20 and d=5, your function should return:

array([[ 0,  1,  2,  3,  4],
       [ 5,  6,  7,  8,  9],
       ...
       [90, 91, 92, 93, 94],
       [95, 96, 97, 98, 99]])

 

def create_array(k, n, d):
   """
   This function returns an n by d matrix with numbers from 0 to k (exclusive) filled in.
   """
   assert (
       n * d == k
   ), "Task 1: The values of n and d are not compatible with the value of k. "

   array = None

   # YOUR CODE HERE

   return array

 

 

# Autograder tests - sanity checks
print(f"Task {task_id} - AG tests")

n, d = 542, 42
k = n * d

stu_ans = create_array(k, n, d)

print(f"Task {task_id} - your answer:n{stu_ans}")

assert isinstance(
   stu_ans, np.ndarray
), "Task 1: Your function should return a np.ndarray. "

assert stu_ans.shape == (
   n,
   d,
), f"Task 1: The shape of your np.ndarray {stu_ans.shape} is not correct. "

assert np.issubdtype(
   stu_ans.dtype, np.integer
), "Task 1: Your np.ndarray should be of an integer type. "

# Some hidden tests below

del k, n, d, stu_ans

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE