24
Jan

Basics on Datatypes / Google Colab Tutorials


In this tutorial video, we will be learning about understanding data types in Python we will learn how arrays of data are handled in the Python language itself and how number pi improves on this Now lets me give you some basic difference between c language and python Some basic difference are in variable declaration In c or java language, requires each variable to be explicitly declared while in python the equivalent operation could be written this way as follows Another difference is switching the contents of an integer to a string In Python language Naming is flexible and we can assign any kind of data to any variable But in C and Java language naming is not flexible and we cannot assign any kind of repeated data to a variable A Python integer is more than just an integer Every Python object is simply a cleverly disguised C structure Integer in Python are actually a pointer which contains several values A single integer in Python 3.4 Actually contains four pieces They are : 1. A reference count that helps python silently handle memory allocation and deal location 2. Which encodes the type of the variable? 3. Which specifies the size of the following data members 4. Which contains the actual integer value that we expect the Python variable to represent? There are some overhead, in storing an integer in Python As illustrated in the following figure Notice the difference here, a C integer is essentially a label for a position in memory whose bytes encode an integer value A Python integer is a pointer to a position in memory containing all the Python object information including the bytes that contain the integer value A Python list is more than just a list The standard mutable multi-element container in python is the list we can create a list of integers as follows and we can check its type And we can also do the same thing to the string list we can create a list of strings as follows and we can check its type like before Because of pythons dynamic typing, we can even create heterogeneous lists But this flexibility comes at a cost to allow these flexible types each item must contain a complete Python object The difference between a dynamic type list and a fixed type array is illustrated in the following figure The Python list, Contains a pointer to a block of pointers Fixed type Numpy style arrays lack this flexibility, but are much more efficient for storing and manipulating data Python offers several different options for storing data in efficient fixed type data buffers The Built in array module can be used to create dense arrays of a uniform type as shown below Here, “i” is a type code indicating the contents are integers Now let’s try on google colab Much more useful However, is the ndarray object of the Numpy package While pythons array object provides efficient storage of array based data Numpy adds to this efficient operations on that data For creating arrays from Python lists We will do it on google colab We need to import numpy First, we can use np.array to create arrays from Python lists Remember that unlike Python lists Numpy is constrained to erase that all contain the same type If types do not match Numpy will up cast impossible If we want to explicitly set the data type of the resulting array, we can use the type keyword Finally, unlike Python lists Numpy arrays can explicitly be multi-dimensional Here’s one way of initializing a multi-dimensional array using a list of Lists Nested lists result in multi-dimensional arrays The inner lists are treated as rows of the resulting two-dimensional array For creating arrays from scratch, we will be doing it on google colab Especially for larger arrays It is more efficient to create arrays from scratch using routines built into Numpy Here are several examples Creating a length of 10 integer array filled with zeros Here, it create a 3×5 floating point array filled with ones Create a 3×5 or a filled with 3.14 Here, it create an array filled with a linear sequence Starting at zero and ending at 20 stepping by 2 It create an array of 5 values evenly spaced between 0 & 1 It create a 3×3 array of uniformly distributed of random values between 0 & 1 Create a 3×3 array of normally distributed random values Create a 3×3 array of random integers in the interval 0 to 10 Create a 3 by 3 identity matrix Lastly, it will create an uninitialized array of three integers and the values will be whatever happens to already exist at that memory location Here are some Numpy standard datatypes Thank you for watching this video and please subscribe to our Channel

Tags: , ,

There are no comments yet

Why not be the first

Leave a Reply

Your email address will not be published. Required fields are marked *