Saved Bookmarks
| 1. |
What are ways of creating 1D, 2D and 3D arrays in NumPy? |
|
Answer» Consider you have a normal python list. From this, we can create NumPy arrays by making use of the array function as follows:
arr = [1,2,3,4] #python list numpy_arr = np.array(arr) #numpy array
arr = [[1,2,3,4],[4,5,6,7]] numpy_arr = np.array(arr)
arr = [[[1,2,3,4],[4,5,6,7],[7,8,9,10]]] numpy_arr = np.array(arr) Using the np.array() function, we can create NumPy arrays of any dimensions. |
|