Trusted by Students Everywhere
Why Choose Us?
0% AI Guarantee

Human-written only.

24/7 Support

Anytime, anywhere.

Plagiarism Free

100% Original.

Expert Tutors

Masters & PhDs.

100% Confidential

Your privacy matters.

On-Time Delivery

Never miss a deadline.

Write function to create an n by d np

Computer Science Feb 24, 2023

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

Expert Solution

For detailed step-by-step solution, place custom order now.
Need this Answer?

This solution is not in the archive yet. Hire an expert to solve it for you.

Get a Quote
Secure Payment