-1

Is it possible to generate random numbers in an nd-array such the elements in the array are between 1 and 2 (The interval should be between 1 and some number greater than 1 )? This is what I did.

input_array = np.random.rand(3,10,10) 

But the values in the nd-array are between 0 and 1.

Please let me know if that is possible. Any help and suggestions will be highly appreciated.

Saurav Rai
  • 2,171
  • 1
  • 15
  • 29

2 Answers2

0

You can try scaling:

min_val, max_val = 1, 2
input_array = np.random.rand(3,10,10) * (mal_val-min_val) + min_val

or use uniform:

input_array = np.random.uniform(min_val, max_val, (3,10,10))
Quang Hoang
  • 146,074
  • 10
  • 56
  • 74
0

You can use np.random.randInt() in order to generate nd array with random integers

import numpy as np

rand_arr=np.random.randint(low = 1, high = 10, size = (10,10))
print(rand_arr)


# It changes randomly
    #Output:
    [[6 9 3 4 9 2 6 2 9 7]
     [7 1 7 1 6 2 4 1 8 6]
     [9 5 8 3 5 9 9 7 8 4]
     [7 3 6 9 9 4 7 2 8 5]
     [7 7 7 4 6 6 6 7 2 5]
     [3 3 8 5 8 3 4 5 4 3]
     [7 8 9 3 5 8 3 5 7 9]
     [3 9 7 1 3 6 3 1 4 6]
     [2 9 3 9 3 6 8 2 4 8]
     [6 3 9 4 9 5 5 6 3 7]]