You can create a 1-dimensional numpy array in Python using the numpy.array()
function. Here's an example:
import numpy as np # create a 1-dimensional numpy array from a list of integers arr = np.array([1, 2, 3, 4, 5]) # print the array print(arr)
Output:
[1 2 3 4 5]
In this example, we first imported the numpy module using the import
statement and then used the np.array()
function to create a 1-dimensional numpy array. We passed a list of integers [1, 2, 3, 4, 5]
to the function to create the array.
You can also create a 1-dimensional numpy array using other data types like floats or strings by passing them in a list to the np.array()
function.