Python Function Guide: Day 5

Hello all,

This is post 5of my 365 posts of re-learning python. I am writing about atlest 5 functions I learned during the day at work here on my post. At the end of 365 days, the aim is to be better at python than I am today.

If you are reading this, this is not a regular tutorial/ how to do this-that page, but a page out my python-re-learning-guide-journal-ish-thing. Only prerequisites are you must know what list, tuple, array, data frame, series and sets.

We were looking into inbuilt functions of python and the remaining few important functions are range() zip() reversed() and sorted() which I have already written about.

There are few functions in python which are dedicated the certain data types, like there are these 11 function dedicated to only list, append(), clear(), copy(), count(), extend(), index(), insert() pop(), remove(), reverse() and sort().These can also be found if you do dir(list()).

The two widely used libraries in python are numpy and pandas.

Numpy is used to work with arrays and we will start with playing around the functions.

For reference of the numpy series I will be using O’reilly book “Python Data Science Handbook” by Jake VanderPlas.

Lets start from understanding how to create arrays from scratch:

1)creating an array of zeros

It takes in the dimension of the array/matrix and numpy also allows to specify the data type.

2) creating an array of ones

It is similar to np.zeros() and takes in the dimension of the array/matrix and numpy also allows to specify the data type.

3) creating an array of all identical values

To create a matrix with all identical values we can create a matrix with np.ones() and just multiply the scalar value to it. Or numpy also has a seperate function np.full() for the same functionality.

4) creating an array with definite step

This function only allows to output an array, where we specify the start and end of the range and the steps. In the example, we specify the range 5 to 15 with step 3, thus the second number is 5+3, 8 and so on.

5) creating an array with given range and equal space

This is similar to np.arange() function, but instead of steps we specify the number of elements we want to divide the range in, here we have given 7 in the example.

6) creating a matrix of random numbers, float values

The function creates a matrix of random float integers.

7) creating a matrix of random numbers but of normal distribution

The function creates a matrix of random float integers, this is similar to np.random.random(), however, here we can also specify mean and standard deviation. Here, we are using mean 1 and standard deviation 10.

8) creating a matrix of random integers

This function is similar to np.random.normal() where we can specify mean and standard deviation, except the numbers in the matrix are integers.

9) creating an identity matrix

This creates a identity matrix, meaning only diagonal elements are one, since rows and column are equal for identity matrix, we need to specify only one number.

Thank you all for reading this.

I only write for self-cognition-process. I am no expert.

If you think there is something I could have done better or I have done wrong, please let me know at methodappend@gmail.com!

I have also started an instagram page. I draw my own drawings (uploaded at the start of the page). Please follow my Instagram handle.(https://www.instagram.com/append_art.py/)

Sharing my notes from self-cognition-process book of python!