Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,859 questions

51,780 answers

573 users

How to use NumPy to generate a list of N 2x3 arrays filled with random numbers between 0 and 1 in Python

1 Answer

0 votes
import numpy as np

# Create and initialize a Random Number Generator (RNG)
rng = np.random.default_rng()

# create a list (lst) containing 4 NumPy arrays
# generate an array with dimensions (2, 3)
# The values in each array follow a normal = between 0 to 1
N = 4
lst = [rng.normal(size=(2, 3)) for _ in range(N)]

print(lst)



'''
run:
 
[array([[ 0.6681934 ,  0.16023812, -0.16074217],
       [-0.02224086, -0.49232873, -0.90910606]]), 
array([[-0.79496191, -0.17465857, -1.52818961],
       [-0.36124112,  1.34770701,  0.48956449]]), 
array([[ 0.49435968,  1.09786444,  2.01169666],
       [-1.31169912, -0.5249541 ,  1.39344048]]), 
array([[ 0.24122752,  1.13007114, -0.25109165],
       [ 0.09214424,  1.21608919, -1.32702621]])]

'''

 



answered Mar 22, 2025 by avibootz
...