How to create NumPy array with specific range values?

We are creating a NumPy array with random values. Suppose I want to create an array that contains values from 0 to 1 or between 1 to 5.

For Example: my_array= [ [ 0.2, 0.999, 0.75, 1, 0.744] ]

Can someone explain to me if it is possible to create this kind of array?

Yes, numpy.ones() function is used to create an array filled with ones. The function takes a tuple as input that specifies the dimensions of the array. You can create a 5x5 matrix of ones and then multiplies it with the row values ranging from 0 to 4 using broadcasting. For example:

The above code uses NumPy’s ones function to create a 5x5 array of ones, and then multiplies each element of the array with the corresponding element of an array generated using NumPy’s arange function. The resulting array is broadcasted to match the shape of the array of ones, stored in a variable and printed to the console using the print function.