Week 8 - NumPy problem

Are these
[[1,2,3,4],
[5,6,7,8]] and
[[1,2],
[3,4]] both 2 dimensions?

If they are, how does np.random.rand(2,3) give a 3 dimension result? Doesn’t this give a result of (for example)
[[0.1,0.2,0.3],
[0.4,0.5,0.6]], which is only 2 dimensions?

Yes both are matrix with 2-d (rows and columns).

The result is again a Matrix with 2 rows and 3 columns (which is 2d).

For creating a 3-d matrix, you can do
np.random.rand(2, 3, 2)
(You can see it as as 2 layers each containing 3 rows and 2 columns)

Thank you Sanjay! Appreciate your prompt response.

1 Like