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,940 questions

51,877 answers

573 users

How to create a 3D array with random numbers in Python

1 Answer

0 votes
import pprint 
import numpy as np

d1 = 6
d2 = 4
d3 = 3

arr = np.random.randint(0, 50, size=(d1, d2, d3))
      
pprint.pprint(arr) 




'''
run:
 
array([[[ 4,  3, 28],
        [48,  3, 26],
        [ 8, 44, 14],
        [48, 36, 31]],

       [[47, 37, 16],
        [ 9,  2, 17],
        [18, 42, 44],
        [11, 24,  8]],

       [[20, 40, 42],
        [ 4, 35,  0],
        [20, 29, 12],
        [21, 39, 21]],

       [[ 2, 14, 11],
        [48, 47,  2],
        [10, 30, 16],
        [13, 13, 26]],

       [[ 2, 46,  3],
        [ 4, 43, 23],
        [40, 41, 23],
        [20, 39, 38]],

       [[11, 38, 15],
        [13, 20, 32],
        [45, 18,  5],
        [49,  2, 27]]])

'''

 



answered Feb 13, 2020 by avibootz

Related questions

2 answers 237 views
1 answer 99 views
1 answer 143 views
1 answer 141 views
141 views asked Oct 26, 2018 by avibootz
...