w3resource logo

:

Python Exercises

Python: Create a 3x3x3 array with random values

Python NumPy: Random Exercise-3 with Solution

Write a Python program to create a 3x3x3 array with random values.

Sample Solution:-

Python Code:

import numpy as np
x = np.random.random((3,3,3))
print(x)

Sample Output:

[[[ 0.08372197  0.09089865  0.54581268]                                
  [ 0.62831932  0.06252404  0.1108799 ]                                
  [ 0.25040264  0.80817908  0.37027715]]                               
                                                                       
 [[ 0.44916756  0.66390614  0.83100662]                                
  [ 0.87831954  0.17075539  0.7506945 ]                                
  [ 0.56165801  0.72280907  0.22771692]]                               
                                                                       
 [[ 0.04956428  0.7143399   0.37042941]                                
  [ 0.78875282  0.27425369  0.88486919]                                
  [ 0.13395418  0.86087257  0.36234729]]]

Python Code Editor:

Improve this sample solution and post your code through Disqus