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.
Australia
UK
UAE
Singapore
Canada
New
Zealand
Malaysia
USA
India
South
Africa
Ireland
Saudi
Arab
Qatar
Kuwait
Hongkong
Copyright 2016-2023 www.programmingshark.com - All Rights Reserved.
Disclaimer : Any type of help and guidance service given by us is just for reference purpose. We never ask any of our clients to submit our solution guide as it is, anywhere.