# ---
# 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
# ---

# # Lab 3 Assignment: 
#
# ### Please type your name here:
# ### Do not forget to change the filename with your name appended
#
# In this lab please fill the indicated cells with your code and explainations, ***run*** everything (select `cell` in the menu, and click `Run all`), save the notebook with your name appended to the filename (for example, `Lab-03-assignment-caos.ipynb`), and upload it to Canvas.
# <br><br>
# This lab assignment contains three problems.
# <br><br>
# Read each problem carefully and answer them the best you can. You may type the code from Lecture notebooks, please do not just copy/paste, rather use type and auto-complete by pressing Tab.

# as always
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# %matplotlib inline

# ## Review: vectorization
# We can create an array using the following line:

arr1 = np.identity(3) + 1 + np.arange(9).reshape(3,3)
arr1

arr2 = np.arange(9).reshape(3,3) + np.array([[1],[5],[9]])
arr2


def myfunc(a, b):
    # Return a-b if a>b, otherwise return a+b
    if a > b:
        return a - b
    else:
        return a + b


# Now directly using this function on an array will give you error.

myfunc(arr1, 2) 
# please delete this cell before submitting, it will give you error and is only for demonstration purpose

print(arr1,"\n")
zs = np.vectorize(myfunc)(arr1, 2)
print(zs) # now this function is applied elementwisely

# ## Problem 1 (graded):
# Create the following 5 by 5 matrix (multi-dimensional array) using a vectorized routine in the `numpy` module (either `float` or `int` is fine).
# ```python
# array([[ 0,  0,  0,  0,  0],
#        [ 0,  1,  2,  3,  0],
#        [ 0,  5,  6,  7,  0],
#        [ 0,  9, 10, 11,  0],
#        [ 0,  0,  0,  0,  0]])
# ```
# *No* `for` nor `while` loops should be used.

# code for Problem 1 here.


# ## Problem 2 (graded)
# Plot the following function g(x) for $x$ in $[-\pi,\pi]$ using `matplotlib` with exactly 1000 points in `np.linspace` function. Use the `math` module to import $\pi$. You can NOT import `math10.py` to do the plot for you.
#
# $ g(x) =
#   \begin{cases}
#     x^{2}\sin\left(x^{3}\right)       & \quad \text{if } x \neq 0\\
#     0 & \quad \text{if } x = 0\\
#   \end{cases}$

# code for Problem 2 here.


# ## Problem 3
#
# Load the `Iris.csv` dataset on Canvas using the following cell, then plot the histograms for all 4 features `SepalLengthCm`, `SepalWidthCm`, `PetalLengthCm`, `PetalWidthCm` in 4 separate figures.
#
# You may use 4 cells to do this, or you may use `subplots` of which the usage can be learned from an example of [matplotlib reference](https://matplotlib.org/gallery/subplots_axes_and_figures/subplots_demo.html).
#
# Reference: Lab 3 practice.



StarcoderdataJupyterScriptsDedupFiltered