A blog for computer science passionates.

Monday, 18 November 2019

How to start ML & DL? NumPy Module Part - 2.6

Hello Friends!!!
Let's start again with NumPy module.
Today's methods for this module are mentioned below and at the end of this article, you will be able to manage numpy array with these methods.
  • linspace
  • empty

Linspace

  • numpy.linspace - this method is used to returns an array. All the numbers are evenly spaced calculated by the first two arguments [start, stop].
    • Syntax: numpy.linspace(start,stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0)
    • Here,  start - represents the starting value of the array that one wants to print or return.
    • step - represents the end value.
    • num - represents number of steps or elements we want to generate. it is an optional argument and it must not any negative number.
    • endpoint - is an optional argument, if it is set to true, it stops when stop element occurs.
    • retstep - is an optional argument, if it is set to true, return elements with a specific step. it simply means return steps.
    • dtype - is an optional argument, the data type of output array. 
    • axis - is an optional argument, the axis in the result to store array elements.
  • It returns two different values
    • elements in the form of ndarray
    • step is optional if retstep argument is set to true.

Empty

  • numpy.empty - returns a new array, of given shape and data type. no need to initialize array.
    • Syntax: numpy.empty(shape,dtype=float,order='C')
    • Here, shape - represents the shape of an array it maybe an integer or tuple.
    • dtype - is an optional argument, to represents data type of an array.
    • order - is an optional argument, to represents how to store data row wise or column wise. if it is in 'C' order, it represents row wise  otherwise 'F' to give column order. 'C' and 'F' represents the name of programming languages 'C' for 'C' language and 'F' for Fortran.
  • It returns ndarray of arbitrary data. 
  • Example,

No comments:

Post a Comment