[Go to site: main page, start]

0% found this document useful (0 votes)
4 views10 pages

Python Dictionary and Numpy Functions Guide

Uploaded by

prince poudel
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views10 pages

Python Dictionary and Numpy Functions Guide

Uploaded by

prince poudel
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

rDictionaries

Dictionary_name.get('Word_not_in_dictionary','What meaning will come')

del Dictionary_name['Word']

Dictionary_name['New word'] = 'Meaning' ---------------- Adding new word

Dictionary_name.pop('Word_to_Delete')--------------------- Deletes the word from dictionary

Dictionary_name.keys()-------------------------------------- Gives the Keys of the dictionary

Dictionary_name.values()________________________> Gives the values

Dictionary_name.items()------------------------------------ Gives the items

Nested Dictionary:

nested_dict = {'dict1':{'Name':'Prince','age':'20'},
'dict2':{'Name':'Bibek','age':'21'}}
print(nested_dict['dict2']['age'])

STRING

Split()--------------------------------------------- Splitting the strings [Changes string into list]

Stringvariable_name.replace("string_character","Another_character")

', '.join(List)-------- It separates the list with the thing inside the Quotation [Changes a list into string]

replace('Old substring','New substring')------------------ Replaces the part of the string by new string.
format():

name = “Prince”

age = “20”

print(“{} is {} years old”.format(name,age))

Regular Expressions:
\ ----------------------------------- Cancel the special meaning of the character following it

+ ----------------------------------- One or more occurances(pr [per peer] ---> /pe+r/)

? ----------------------------------- Optional sign (Men Mens---> /Mens?/)

* ----------------------------------  Matches any number of occurances including 0


occurances(br ber beer---> /be*r/)

. ----------------------------------- Matches anything(a character except a new line) at all

\w ----------------------------------- Matches every word character

{a,b} ----------------------------------- Matching the character from a to b(pr per [peer] peeer---->
/pe{2}r/)

pe{a,b}r -------------> e can occur a to b times


[ab]nt ------------------------------------ Matches the characters with nt that starts with a or b

() ------------------------------- Grouping : Ta-Ta,Taa-Taa : (Ta)-\1,(Taa)-\2

(?:Ta)-Ta,(Taa)-\1: Grouping without Refrencing

$ -------------------------------- Matches at the end of the line

^ ------------------------------- Matches at the beginning(Bracket outside), Except(Bracket inside)

(?=) ------------------------------ Positive Lookahead

(?!) ------------------------------- Negative Lookahead

(?<=) --------------------------------- Positive lookbehind

(?<!) ----------------------------------- Negative lookbehind

REMEMBER: Underscore(_) comes in Word Character.

w = Word Character

W = Except Word Character.

\s = White Space

\b = Word boundary(,. etc)

\B = Not a word boundary

Regex functions:
Lambda Function

LIST

[Link]()----------- adds the item into the list at the end

[Link](position,value)------------ inserts the item into the list at a specific position

[Link]()

Randomness in python:
[Link](2)

[Link]()
[Link]() This gives a random value between 0 and 1.
Random function with parameters
[Link](a,b) Generates Random integer between a and b
[Link](a,b,c) a=start value,b=End Value, c= step between two
values(Difference)
[Link](list_name)

In keyword in Python:

1) For checking the items in the list,dictionary and tuples etc.


2) For checking the character in the string.

Creating NumpyArrays

1)By Transforming standard list

2)Built in functions

3) Generating random data

[Link](list_name)---------------------- Turns a list into a numpy array

Numpy knows the dimensional of the array.

[Link](Start,Finish,Steps): It doesnot include the end number

[Link](1,10,2):

1,3,5,7,9

[Link](Rows,Coloums,)
[Link](Start,End,Number of numbers):------ It includes the end number as well

[Link](Dimension)------------------ Creates the Identity matrix

[Link](num)--------------- it will pick a random number between (0,1]

[Link](num)-------------- Gives normal distribution(which has mean = 0, SD = 1)

k = [Link] (Low_value, Higher_value,Size) It takes end number

[Link]()-- Gives the max value in the array

[Link]()-- Gives the minimum value in the array

[Link]()- Gives the index of the max value in the array

[Link]()-- Gives the index of the minimum value of the array

[Link](a,[4,5]) Gives 4,5 from the list

[Link](a) ---------- Returns True for numbers except Zero [Link]()

[Link]()--- Checks whether the number is finite or not np. isreal()

[Link]------- It is used to represent NAN number [Link]().-->Checks ComplexNum

[Link]------ it is useful to represent an infinite number in python we make complex num using j

[Link]() [Link]() Checks scalar or not

[Link]() [Link]-- Gives the size of an array

[Link](a) [Link]((x,y)) gives ones in a matrix

[Link]()----- Compares two arrays with tolerance [Link](3,3)--- Rehsapes the


structure

[Link] or greater or greater_equal or less_equal() [Link]([1,2,3,4,5]) Broadcast on [Link]

[Link](“filename”,array) [Link](“filename”,array,fmt,header)

[Link](“filename”) [Link](“filename”)

[Link](a) [Link](a)/ [Link](a)-- For S.D and Variance of an array

[Link]()->For covariance [Link](x, y)- For crosssection [Link](No of times)


[Link](a)—Counts the no of occurrence of number from min to max

[Link](a,axis = 0/1)

np.count_nonzeros(a) [Link]() For matrix multiplication [Link](arr,axis)[where


axis:0=Coloumn and axis 1 = Along Row]

[Link](column,no_of_decimels)

[Link](Seed_number) + [Link]()

axis in array : axis = 0[Along Rows i.e Coloumn elements], [axis = 1= Along Coloumn = rows
elements]

OS library functions:

[Link](‘file’)- Search for the path of the file in the same directory.

Indexing and selection in NUMPY


A = [Link][2:8]------ It will grab the value of 2 upto 7 i.e not including 8

n[1:6] = 19--------------- Broadcasting

SLICING IN THE ARRAY

N = [Link](0,11)

P = N[0:6]
Print(P)--------------- Output: 0,1,2,3,4,5

P[0:] = 1

print(P)----------- [1,1,1,1,1,6,7,8,9,10]

Slicing Through condition:

MATPLOTLIB

[Link](lisx,lisy,s = ,c = ‘’,marker = ‘*’,alpha = 0-1)

[Link](lisx,lisy,c = ‘red’,linestyle = ‘:’,lw = 1)

[Link](xlis,ylis,color = ‘Yellow’,width = 0-1,edgecolor = ‘pink’,lw =5)

[Link](x) ---- For Histogram


CREATING A LINE:

[Link](x,y)

[Link](‘TITLE_NAME’)

[Link](start_num,End_num)

[Link](start_num,End_num)

[Link](‘X-Axis’)

[Link](‘Y-Axis’)

[Link](‘Figure_Name.jpg/jpeg/png’)

Making the figure Object:

fig = [Link]() ------- Setting the figure function as fig

axes = fig.add_axes([0,0,1,1]) where 0,0 = Left Corners and 1,1 = Weight,Height

[Link](x,y)

This all should be done within a single shell in Jupyter Notebook.

USING SUBPLOTS FOR Figure and the Axes:

fig,axes = [Link](nrows,ncols,color = ‘Red’,linewidth = 3) ---- This creates axes of


dimension nrows,ncols

axes[0][0].plot(x,y,ls = ‘--’,lw = 10,color = ‘’)

axes[1,1].plot(a,b)

fig.tight_layout() ----- This function makes sure not to overlap anything.

[Link](wspace = 1,hspace = 1) --- It helps to adjust the spacing between axes.

[Link]()

axes.set_title() -------- For giving title to the axes

You might also like