A blog for computer science passionates.

Wednesday, 6 November 2019

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

Hello Friends!!!
This article takes some time, as I do work on some other articles also. Let's again work on NumPy, Kudos you all have learned some methods already from other articles of this module successfully. Now let's start with new methods with examples.
image (source: pixabay.com): Peoples are in a queue and new peoples are appended to the queue at the end of line
  • numpy.append - This method is used to add (append)new values in an array at the end. 
    • Syntax: numpy.append(array,values,axis=None)
    • Here, array - is array-like values to be appended to the copy of the main array.
    • values - is array-like values to be appended to the copy of the first argument array. it should be the same shape as the first argument has.
    • axis - is an optional argument. it is used to set the axis on which array and values are to be appended.
  • It returns ndarray object. copy array with values to the axis and append to ndarray.
  • Example,
  • It also gives ValueError, if axis of the array and values are different.

  • numpy.insert - This method is used to insert element(s) on specific index.
    • Syntax: numpy.insert(array,index,values,axis=None)
    • Here, array - is an array.
    • index - is an integer value that defines an index on which values are inserted. Even we can pass multiple integer indexes in the form of an object.
    • values - is values to be inserted in an array.
    • axis - is an optional argument, it is used to set the axis on which array and values are to be inserted.
  • It returns ndarray object with all inserted values to the array.
  • Example,
  • Now, you can find the difference between append and insert. There is a simple difference through append you can insert an element at the end of the array only and through insert method, you can insert element(s) on any indexes that you have mentioned in index argument.
So, that's it for this article, in the next article we'll learn more methods.
Enjoy and learn new things every day, every time...☺😊

No comments:

Post a Comment