# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # DataScience Course $\circ$ Python Programming $\circ$ Numpy Arrays
# By Dr <NAME>  
# <img src="https://1.bp.blogspot.com/-J1gxIX6Cp9w/Wy-lUTT-LqI/AAAAAAADIss/i8oWgsmB9OY8nRMc21XH_BA7AUCGkuGFgCLcBGAs/s1600/logo2.jpg" width=600> 
# <hr>

# ### Topics
# - Using numpy 
#     - package installation
#     - numpy import
# - numpy arrays
# - linspace
# - eye
# - random

# +
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# %matplotlib inline

rs = np.random.RandomState(0)
M = rs.randint(1, 100, 20)
M_cumsum = np.ones(20)*M.mean()

def plot_M():
    plt.figure(figsize=(10,5))
    x = list(range(1, len(M)+1))
    sns.barplot(x, M)
    sns.pointplot(x, M_cumsum, markers='+') ;
# -

# ## Exercises
# - Run provided codes prior to the exercise question
# - Add a **new cell** to try your code
# - Type in Python code in the box to get the results as displayed right below
#
# __Warning__: results will be replaced, so make sure you add a new cell to try your code

# **$\Rightarrow$ 
# Import the package `numpy` as `np`
# **



# **$\Rightarrow$ 
# Use `arange` to create a numpy array of 100 items, assign it to `x`
# **



# **$\Rightarrow$
# Use `linspace` to create a numpy array of 100 items, assign it to `y`
# **



# **$\Rightarrow$
# Generate a [10, 5] matrix (2d array) of normally distributed numbers, assign it to `M1`
# **



# **$\Rightarrow$
# Compute the mean along all the 10 rows of `M`
# **



# **$\Rightarrow$
# Compute the max along all the 5 columns of `M`
# **



# **$\Rightarrow$
# Create the following matrix `M2` with the help of `eye`, `ones`, and `arange` functions
# **
# ```
# array([[  2.,   2.,   3.,   4.,   5.],
#        [  6.,   8.,   8.,   9.,  10.],
#        [ 11.,  12.,  14.,  14.,  15.],
#        [ 16.,  17.,  18.,  20.,  20.],
#        [ 21.,  22.,  23.,  24.,  26.]])
# ```



# **$\Rightarrow$
# Find the index of the maximum value in `M`
# **



# ** OPTIONAL $\Rightarrow$
# Compute the cumulative sum of `M` using the method `cumsum` and assign it to `M_cumsum`
# Then rerun the function `plot_M()`
# **





# <hr>
# ## Finished !

StarcoderdataJupyterScriptsDedupFiltered