<jupyter_start><jupyter_text>Assignment - 
From the above array, retrieve the values([[3,4],[5,6]]) using indexing<jupyter_code>import numpy as np

lst1 = [1,2,3,4,5]
lst2 = [2,3,4,5,6]
lst3 = [4,5,6,7,8]

arr1 = np.array([lst1, lst2, lst3])
arr1
# for [[3,4],[5,6]]
arr1[1:,1:3]
# for [[3,4,5,6]]
arr1[1:2,1:]<jupyter_output><empty_output><jupyter_text>Welcome to Day 2 of Ëssentials program - "Python for Data Science" Dictionary<jupyter_code>person1 = {
    'name': '<NAME>',
    'sex': 'Male',
    'age': 32,
    'married': True
}
person1
type(person1)
person2 = dict(name='<NAME>', sex='Female', age=28, married=False)
person2
type(person1)
person1['age']
#person1['address']   #### If a key isn't present in the dictionary, then a KeyError is thrown.<jupyter_output><empty_output><jupyter_text>You can also use the get method to access the value associated with a key.<jupyter_code>person2
person2.get("name")
person1
person1['address'] = '1, Penny Lane'
person1<jupyter_output><empty_output><jupyter_text>To remove a key and the associated value from a dictionary, use the pop method.<jupyter_code>person1
person1.pop('address')
person1
person1.keys()
person1.values()
person1.items()<jupyter_output><empty_output><jupyter_text>Defining functionsBuiltin functions are great, but we can only get so far with them before we need to start defining our own functions. Below is a simple example:<jupyter_code>a=30
b=20
c=10

print("diff1 = a-b =", abs(a-b))
print("diff2 = b-c =", abs(b-c))
print("diff3 = a-c =", abs(a-c))

print("least difference =", min(abs(a-b), abs(b-c), abs(c-a)))
def least_difference(a, b, c):
    diff1 = abs(a - b)
    diff2 = abs(b - c)
    diff3 = abs(a - c)
    return min(diff1, diff2, diff3)<jupyter_output><empty_output><jupyter_text>This creates a function called least_difference, which takes three arguments, a, b, and c.Functions start with a header introduced by the def keyword. The indented block of code following the : is run when the function is called.return is another keyword uniquely associated with functions. When Python encounters a return statement, it exits the function immediately, and passes the value on the right hand side to the calling context.<jupyter_code>print(
    least_difference(1, 10, 100),
    least_difference(1, 10, 10),
    least_difference(5, 6, 7))
help(least_difference)<jupyter_output>Help on function least_difference in module __main__:

least_difference(a, b, c)<jupyter_text>DocstringsThe docstring is a triple-quoted string (which may span multiple lines) that comes immediately after the header of a function. When we call help() on a function, it shows the docstring.<jupyter_code>def least_difference(a, b, c):
    """Return the smallest difference between any two numbers
    among a, b and c.
    
    >>> least_difference(1, 5, -5)
    4
    """
    diff1 = abs(a - b)
    diff2 = abs(b - c)
    diff3 = abs(a - c)
    return min(diff1, diff2, diff3)
help(least_difference)
## Functions that don't return
## What would happen if we didn't include the return keyword in our function?
def least_difference(a, b, c):
    """Return the smallest difference between any two numbers
    among a, b and c.
    """
    diff1 = abs(a - b)
    diff2 = abs(b - c)
    diff3 = abs(a - c)
    min(diff1, diff2, diff3)
    
print(
    least_difference(1, 10, 100),
    least_difference(1, 10, 10),
    least_difference(5, 6, 7),
)<jupyter_output>None None None<jupyter_text>Python allows us to define such functions. The result of calling them is the special value None. (This is similar to the concept of "null" in other languages.)Without a return statement, least_difference is completely pointless, but a function with side effects may do something useful without returning anything.  Default arguments we can specify a value for sep to put some special string in between our printed arguments:<jupyter_code>print(1, 2, 3, sep=' < ')<jupyter_output>1 < 2 < 3<jupyter_text>If-else statements in Python<jupyter_code>a_number = 34

if a_number % 2 == 0:
    print('The given number {} is even.'.format(a_number))
else:
    print('The given number {} is odd.'.format(a_number))
b = 33
if b % 2 == 0:
    print('The given number {} is even.'.format(b))
else:
    print('The given number {} is odd.'.format(b))<jupyter_output>The given number 33 is odd.<jupyter_text>The `elif` statementPython also provides an `elif` statement (short for "else if") to chain a series of conditional blocks. The conditions are evaluated one by one. For the first condition that evaluates to `True`, the block of statements below it is executed. The remaining conditions and statements are not evaluated. So, in an `if`, `elif`, `elif`... chain, at most one block of statements is executed, the one corresponding to the first condition that evaluates to `True`.<jupyter_code>a_number = 15
if a_number % 2 == 0:
    print('{} is divisible by 2'.format(a_number))
elif a_number % 3 == 0:
    print('{} is divisible by 3'.format(a_number))
elif a_number % 5 == 0:
    print('{} is divisible by 5'.format(a_number))
elif a_number % 7 == 0:
    print('{} is divisible by 7'.format(a_number))
15%2<jupyter_output><empty_output><jupyter_text>**What is the NumPy library in Python?**NumPy stands for Numerical Python and is one of the most useful scientific libraries in Python programming. It provides support for large multidimensional array objects and various tools to work with them. Various other libraries like Pandas, Matplotlib, and Scikit-learn are built on top of this amazing library.Arrays are a collection of elements/values, that can have one or more dimensions. An array of one dimension is called a Vector while having two dimensions is called a Matrix.NumPy arrays are called ndarray or N-dimensional arrays and they store elements of the same type and size. It is known for its high-performance and provides efficient storage and data operations as arrays grow in size.<jupyter_code>import numpy as np
my_lst =[1,2,3,4,5]
type(my_lst)
arr = np.array(my_lst)
arr
arr.shape    ### 1-D array
## multinested array

lst1 = [1,2,3,4,5]
lst2 = [2,3,4,5,6]
lst3 = [4,5,6,7,8]

arr1 = np.array([lst1, lst2, lst3])
arr1
arr1.shape
arr1.reshape(5,3)<jupyter_output><empty_output><jupyter_text>Indexing<jupyter_code>arr = np.array([1,2,3,4,5,6,7,8])
arr
arr[2:5]
arr1
arr1[0:2,0:2]
arr1[1:,3:]<jupyter_output><empty_output><jupyter_text>Assignment:
From the above array, retrieve the values([[3,4],[5,6]]) using indexing<jupyter_code>arr = np.arange(0,10)
arr
arr = np.arange(0,10,step=3)
arr
np.linspace(1,10,50)
arr
arr[3:] = 100
arr
np.ones(5)
np.ones(5, dtype=int)
np.zeros(4)
np.random.rand(3,3)
arr_x = np.random.randn(4,4)
arr_x
import pandas as pd
import seaborn as sns
sns.distplot(pd.DataFrame(arr_x.reshape(16,1)))<jupyter_output>/usr/local/lib/python3.7/dist-packages/seaborn/distributions.py:2557: FutureWarning: `distplot` is a deprecated function and will be removed in a future version. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or `histplot` (an axes-level function for histograms).
  warnings.warn(msg, FutureWarning)
{'fraction_non_alphanumeric': 0.11501730103806228, 'fraction_numerical': 0.03432525951557094, 'mean_word_length': 4.627725856697819, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '253964', 'license': 'MIT', 'n_tokens_mistral': 2537, 'n_tokens_neox': 2414, 'n_words': 831, 'path': 'Python for Data Science Zero to Hero/Day-2.ipynb', 'repo_name': 'Rohan-Somadder/Lets_Upgrade', 'size': '7230'}