empty()
method doesThe empty()
method one of the methods you can use to create a NumPy array. However, the difference between this method and the other methods that are used to create an array, is the empty()
function creates an
empty()
accept?The empty()
function accepts three parameters:
shape: This specifies the shape of the array that you want to create. This value could be an int
, like 2, or a tuple of int
, like (2, 3).
dtype: This is an optional parameter that specifies the data type of your array. By default, its value is float
.
order: This is also an optional parameter. It specifies how you want to store elements in a multi-dimensional array. It can have two values:
By default, the value of this parameter is ‘C’.
empty()
return?The empty()
function return an n-dimensional array.
empty()
functionTake a look at the code snippet below and use the empty()
function.
import numpy as np one_darray = np.empty(3) print(one_darray) two_darray = np.empty([3,3]) print(two_darray) two_darray_int = np.empty([3,3], dtype=int) print(two_darray_int)
Explanation:
float
valuesfloat
valuesint
valuesSo, this is how you can create an
RELATED TAGS
CONTRIBUTOR
View all Courses