Python numpy.ones()

In this tutorial, i’ll  talk about python numpy ones() function. It returns an array of ones.

Syntax:

the syntax of python numpy ones() function is

 

Parameter:

Numpy ones() function can take three parameters:

  • shape: it defines the shape of the new array
  • dtype(optional): It assign a datatype to array, by default is float64
  • order(optional): C-style order in memory or F- Style order in memory. If multi-dimensional array in row major then C-style order in memory and if multi-dimensional array in column-major then F-style order in memory. By defualt , its C-style

Check examples below to understand

 

Example #1

creating a ones array

 

 

Example #2

creating a ones array with int data type

 

 

Example#3

creating a 2-denominational ones array , including with 2 rows and three columns

 

 

Example#4

creating a 2-denominational ones array with int data type , including with 2 rows and three columns

 

 

Example#5

creating a three dimensional ones array with int data type and F-style order

 

 

Start with Numpy

Python numpy.zeros()