![]() |
VOOZH | about |
One-dimensional array contains elements only in one dimension. In other words, the shape of the NumPy array should contain only one value in the tuple. We can create a 1-D array in NumPy using the array() function, which converts a Python list or iterable object.
[1 2 3 4 5]
Let's explore various methods to Create one- dimensional Numpy Array.
Table of Content
arrange() returns evenly spaced values within a given interval.
[3 5 7 9]
Linspace() creates evenly space numerical elements between two given limits.
Output:
[ 3. 6.5 10. ]Fromiter()is useful for creating non-numeric sequence type array however it can create any type of array. Here we will convert a string into a NumPy array of characters.
Output:
['g' 'e' 'e' 'k' 's' 'f' 'o' 'r' 'g' 'e' 'e' 'k' 's']Zeros() returns the numbers of 0s as passed in the parameter of the method
Output:
[0.0.0.0.0]ones() returns the numbers of 1s as passed in the parameter of the method
[1. 1. 1. 1. 1.]
Random() return the random module provides various methods to create arrays filled with random values.
[[0.07752187 0.74982957 0.53760007] [0.73647835 0.62539542 0.27565598]]