12.8) Exercise 35 - Creating Arrays
What are the Python commands to:
- Create an array from the list [[23,45.5,3],[34,56.3,4]]?
- Create a vector (1D array) with integers from 3 to 5 (inclusive)?
- Create a array with 2 columns and 5 lines filled with 0.0?
- Create a three dimensional arrays of shape (3,4,2) filled with 1 (integers)?
- Create a two dimensional array that is 3by3 and filled with NaNs?
- Create a two dimensional array 3by3 filled with 5.5?
[tippy title="Solution 1"]
np.array([[23,45.5,3],[34,56.3,4]])
[/tippy]
[tippy title="Solution 2"]
np.arrange(3,6)
[/tippy]
[tippy title="Solution 3"]
np.zeros((5,2))
[/tippy]
[tippy title="Solution 4"]
np.ones((3,4,2),dtype='i')
[/tippy]
[tippy title="Solution 5"]
A=np.empty((3,4,2)) A[:]=np.nan # OR A[:]=None
[/tippy]
[tippy title="Solution 6"]
np.ones((3,4,2)) * 5.5 # OR A=np.empty((3,4,2)) A[:]=5.5
[/tippy]