Understand numpy.full(): Create an Array with Given Shape and Value – NumPy Tutorial

By | September 15, 2019

numpy.full() function can allow us to create an array with given shape and value, in this tutorial, we will introduce how to use this function correctly.

Syntax

numpy.full(shape, fill_value, dtype=None, order='C')

Return a new array of given shape and type, filled with fill_value.

Parameters

shape : Shape of the new array, e.g., (2, 3) or 2.

fill_value : scalar, eg., 5.0

dtype : data-type, optional, eg., np.float32

Return

return a new array

Here are some examples

Create a 3*2 matrix with value 4.0

import numpy as np

arr = np.full((3, 2), 4.0)
print(arr)

The new array is:

[[ 4.  4.]
 [ 4.  4.]
 [ 4.  4.]]

Leave a Reply