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

## NumPy: Array Object Exercise-55 with Solution

Write a NumPy 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:

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

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz

﻿

## Python: Tips of the Day

Set comprehension:

```>>> m = {x ** 2 for x in range(5)}
>>> m
{0, 1, 4, 9, 16}
```