numpy.ones() in Python

Python numpy.ones() function returns array of given size and shape filled with ones (1’s). In another words it will return array which is filled with 1’s.

Basic Syntax

Following is the basic syntax for numpy.ones() function in Python:

numpy.ones(shape, dtype = None, order = ‘C’)

And the parameters are:

ParameterDescription
shapeThis parameter specifies integer of sequence of integers.
dtypeOptional. The data type of array elemnts that will be returned.
orderOptional. For row major provide C or for column major provide F (Fortron style) to store multi-dimensional data in memory.

Return Value

numpy.ones() function returns array filled with 1’s.

Example

Following is the example of numpy.ones() function

The output for the above program is as given below:

Array first :
[1, 1, 1, 1]Array second :
[[1, 1, 1],
[1, 1, 1],
[1, 1, 1]]

Array third :
[[ 1., 1.],
[ 1., 1.]]

LEAVE A REPLY

Please enter your comment!
Please enter your name here