1

I would like to create two random arrays in NumPy for a fixed, given shape. np.random.randn(A,B,C) creates a random array of float64, if i am not mistaken, how do i create one filled with float32?

If i am mistaken, then my question still pertains, just the other way around.

Mazdak
  • 105,000
  • 18
  • 159
  • 188
Clebo Sevic
  • 581
  • 1
  • 7
  • 17

2 Answers2

4

You can convert your array after initialization as follow :

mat = np.random.randn(A,B,C)
mat = mat.astype(np.float32)
Alexis Pister
  • 449
  • 3
  • 13
1

You can pass dtype as follows:

np.array(np.random.randn(1,2,3), dtype=np.float32)
Umesh
  • 941
  • 5
  • 12