w3resource logo
Python Exercises

Python NumPy: Convert specified inputs to arrays with at least one dimension

Python NumPy: Array Object Exercise-54 with Solution

Write a Python program to convert specified inputs to arrays with at least one dimension.

Sample Solution:-

Python Code:

import numpy as np
x= 12.0
print(np.atleast_1d(x))
x = np.arange(6.0).reshape(2, 3)
print(np.atleast_1d(x))
print(np.atleast_1d(1, [3, 4]))

Sample Output:

[ 12.]                                                                 
[[ 0.  1.  2.]                                                         
 [ 3.  4.  5.]]                                                        
[array([1]), array([3, 4])] 

Python Code Editor:

import numpy as np
x= 12.0
print(np.atleast_1d(x))
x = np.arange(6.0).reshape(2, 3)
print(np.atleast_1d(x))
print(np.atleast_1d(1, [3, 4]))

Improve this sample solution and post your code through Disqus