Skip to main content

Posts

Showing posts from August, 2019

Lists in Python, Slicing, for loops

# In[1]: bicycles=['trek', 'redline', 'Hero'] print (bicycles) # In[2]: print(bicycles[0].title()) # In[4]: bicycles[0]='Ranger' # In[5]: print(bicycles) # In[6]: bicycles.append('Trek') # In[8]: print(bicycles) # In[7]: bicycles.insert(1,'Hercules') # In[10]: print(bicycles) # In[12]: bicycles.pop() # In[13]: print(bicycles) # In[14]: bicycles.pop(0) # In[15]: print(bicycles) # In[16]: cars = ['bmw','audi','toyota','benz'] # In[17]: print(cars) # In[ ]: #Slicing in Python # In[20]: Pavan = [1,2,3,4,5,6,7,8,9,10] # In[21]: print(Pavan) # In[22]: Pavan.slice[4] # In[23]: Pavan = Slice[4] # In[24]: Pavan[1:3] # In[25]: Pavan[0:] # In[26]: Pavan[:6] # In[27]: Pavan[4:11] # In[28]: Pavan[9:29] # In[21]: Pavan[0:11:4] # In[30]: Pavan[::] # In[31]: Pavan[:] # In[32]: Pavan[:-1...

Arrays and Matrices in Python

# In[1]: import numpy as np # In[2]: # Array of ones using matrix array_of_ones = np.ones((3,4)) # (3,4) is (x,y) where x is no of rows and y is no of cols array_of_ones # In[13]: # How to specify te data type? # We use dtype function array_of_ones_int = np.ones((4,5),dtype=np.int16) array_of_ones_int # In[15]: #Or array_of_ones_int = np.ones((4,5),dtype=int) array_of_ones_int # In[16]: array_of_ones_bool = np.ones((4,5),dtype=bool) array_of_ones_bool # In[18]: array_of_ones_str = np.ones((3,5),dtype=str) array_of_ones_str # In[19]: array_of_ones_float = np.ones((3,5),dtype=float) array_of_ones_float # In[20]: array_of_ones_float1 = np.ones((3,5)) # By default it gives a float value, without declaring the data type array_of_ones_float1 # In[21]: array_empty = np.empty((2,3)) array_empty # In[22]: # How to create identity matrix #np.eye() array_eye = np.eye(3) array_eye # In[23]: # range is in Python # ar...

Python programming with NumPy

get_ipython().system('pip install numpy') # In[5]: get_ipython().system('pip install --upgrade pip') # In[7]: get_ipython().system('pip install numpy --upgrade') # In[ ]: # What is NumPy? # Numpy is a numerical computing package! # Pyhton cannot support the functionality what numpy provides directly # Basic building block of Numpy is a powerful n dimentional array # In[9]: import numpy as np array_one = np.array([1,2,3,4]) array_one # In[10]: number = [22,33,44,55,66] array_two = np.array(number) array_two # In[11]: # array of zeros array_zeros = np.zeros((4,5)) array_zeros # In[ ]: # Source: https://www.machinelearningplus.com/python/101-numpy-exercises-python/ # Q. Import numpy as `np` and print the version number. # In[14]: import numpy as np get_ipython().system('pip install numpy') # In[15]: #or import numpy as np print(np.__version__) # In[ ]: # Q. Create a 1D array of numbers ...

A quick introduction to Python

Python (programming language)  Python is an interpreted, high-level, general-purpose programming language. Created by Guido van Rossum and first released in 1991, Python's design philosophy emphasizes code readability with its notable use of significant whitespace. Its language constructs and object-oriented approach aim to help programmers write clear, logical code for small and large-scale projects. Python is dynamically typed and garbage-collected. It supports multiple programming paradigms, including procedural, object-oriented, and functional programming. Python is often described as a "batteries included" language due to its comprehensive standard library. Python was conceived in the late 1980s as a successor to the ABC language. Python 2.0, released 2000, introduced features like list comprehensions and a garbage collection system capable of collecting reference cycles. Python 3.0, released 2008, was a major revision of the language that is not complet...