Ask Question
30 July, 19:49

Write a python function genRandomVect that returns a random 1d numpy array of size (50,) where each element is an integer sampled from [0, 100) and no two elements in the vector are the same.

Your code snippet should define the following variable:

Name Type Description

genRando function function that returns a numpy array of shape (50,) that

contains random elements on the interval [0, 100) and

no duplicates

+5
Answers (1)
  1. 30 July, 22:29
    0
    import numpy as np

    def genRandomVect ():

    arr = np. random. choice (range (100), size = (50,), replace=False)

    return arr

    print ("Random 1D numpy array where each element is an integer sampled from: [0, 100) ")

    print (genRandomVect ())

    Explanation:

    Create a function to create a numpy array with random integers in range[0,100) with no duplicates Use the random. choice to select random values from range[0,100) and size attribute to take the size of the required array. Finally return the numpy array.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a python function genRandomVect that returns a random 1d numpy array of size (50,) where each element is an integer sampled from [0, ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers