﻿ Python NumPy: View inputs as arrays with at least two dimensions, three dimensions - w3resource

Python NumPy: View inputs as arrays with at least two dimensions, three dimensions

Python NumPy: Array Object Exercise-55 with Solution

Write a Python program to view inputs as arrays with at least two dimensions, three dimensions.

Sample Solution:-

Python Code:

``````import numpy as np
x = 10
print("View inputs as arrays with at least two dimensions:")
print(np.atleast_1d(x))
x = np.arange(4.0).reshape(2, 2)
print(np.atleast_1d(x))
print("View inputs as arrays with at least three dimensions:")
x =15
print(np.atleast_3d(x))
x = np.arange(3.0)
print(np.atleast_3d(x))
```
```

Sample Output:

```View inputs as arrays with at least two dimensions:
[10]
[[ 0.  1.]
[ 2.  3.]]
View inputs as arrays with at least three dimensions:
[[[15]]]
[[[ 0.]
[ 1.]
[ 2.]]]
```

Python Code Editor:

```import numpy as np
x = 10
print("View inputs as arrays with at least two dimensions:")
print(np.atleast_1d(x))
x = np.arange(4.0).reshape(2, 2)
print(np.atleast_1d(x))
print("View inputs as arrays with at least three dimensions:")
x =15
print(np.atleast_3d(x))
x = np.arange(3.0)
print(np.atleast_3d(x))```

Improve this sample solution and post your code through Disqus