<jupyter_start><jupyter_text>>  **Assignment 2 - Numpy Array Operations** >> This assignment is part of the course ["Data Analysis with Python: Zero to Pandas"](http://zerotopandas.com). The objective of this assignment is to develop a solid understanding of Numpy array operations. In this assignment you will:> > 1. Pick 5 interesting Numpy array functions by going through the documentation: https://numpy.org/doc/stable/reference/routines.html > 2. Run and modify this Jupyter notebook to illustrate their usage (some explanation and 3 examples for each function). Use your imagination to come up with interesting and unique examples.> 3. Upload this notebook to your Jovian profile using `jovian.commit` and make a submission here: https://jovian.ml/learn/data-analysis-with-python-zero-to-pandas/assignment/assignment-2-numpy-array-operations> 4. (Optional) Share your notebook online (on Twitter, LinkedIn, Facebook) and on the community forum thread: https://jovian.ml/forum/t/assignment-2-numpy-array-operations-share-your-work/10575 . > 5. (Optional) Check out the notebooks [shared by other participants](https://jovian.ml/forum/t/assignment-2-numpy-array-operations-share-your-work/10575) and give feedback & appreciation.>> The recommended way to run this notebook is to click the "Run" button at the top of this page, and select "Run on Binder". This will run the notebook on mybinder.org, a free online service for running Jupyter notebooks.>> Try to give your notebook a catchy title & subtitle e.g. "All about Numpy array operations", "5 Numpy functions you didn't know you needed", "A beginner's guide to broadcasting in Numpy", "Interesting ways to create Numpy arrays", "Trigonometic functions in Numpy", "How to use Python for Linear Algebra" etc.>> **NOTE**: Remove this block of explanation text before submitting or sharing your notebook online - to make it more presentable. Numpy Array Functions Five PicksFunctions belows are my five chosen functions from Numpy module. - function1 = np.concatenate- function2 = np.transpose- function3 = np.vstack- function4 = np.hsplit- function5 = np.linalgThe recommended way to run this notebook is to click the "Run" button at the top of this page, and select "Run on Binder". This will run the notebook on mybinder.org, a free online service for running Jupyter notebooks.<jupyter_code>!pip install jovian --upgrade -q
import jovian
jovian.commit(project='numpy-array-operations')<jupyter_output><empty_output><jupyter_text>Let's begin by importing Numpy and listing out the functions covered in this notebook.<jupyter_code>import numpy as np
# List of functions explained 
function1 = np.concatenate  
function2 = np.transpose 
function3 = np.vstack
function4 = np.hsplit
function5 = np.linalg<jupyter_output><empty_output><jupyter_text>Function 1 - np.concatenateArray indexing is the same as accessing an array element.<jupyter_code># Example 1 - working (change this)
arr1 = [[1, 2], 
        [3, 4.]]

arr2 = [[5, 6, 7], 
        [8, 9, 10]]

np.concatenate((arr1, arr2), axis=1)
# Example 2 - working
arr1 = [[1, 2, 9], 
        [3, 4., 0]]

arr2 = [[5, 6, 7], 
        [8, 9, 10]]

np.concatenate((arr1, arr2), axis=1)
# Example 3 - breaking (to illustrate when it breaks)
arr1 = [[1, 2], 
        [3, 4.]]

arr2 = [[5, 6, 7], 
        [8, 9, 10]]

np.concatenate((arr1, arr2), axis=0)<jupyter_output><empty_output><jupyter_text>Some closing comments about when to use this function.<jupyter_code>jovian.commit()<jupyter_output><empty_output><jupyter_text>Function 2 - TransposeAdd some explanations<jupyter_code># Example 1 - working
 
arr1 = [[1, 2], 
        [3, 4.]]


i = np.transpose(arr1)
print(i)<jupyter_output><empty_output><jupyter_text>Example 2 shows how to create an empty array. Despite it's name np.empty() does not generate empty array but array of random data.<jupyter_code># Example 2 - working
arr2 = [[10, 2], 
        [30, 4.]]


i = np.transpose(arr2)
print(i)<jupyter_output><empty_output><jupyter_text>Explanation about example<jupyter_code># Example 3 - breaking (to illustrate when it breaks)
arr2 = [[10, 2], 
        [30, 4.]]


i = np.transpose(arr3)
print(i)<jupyter_output><empty_output><jupyter_text>Explanation about example (why it breaks and how to fix it) Some closing comments about when to use this function.<jupyter_code>jovian.commit()<jupyter_output><empty_output><jupyter_text>Function 3 - np.vstackAdd some explanations<jupyter_code># Example 1 - working
a = [[1, 2], 
    [3, 4.]]

b = [[10, 2], 
    [3, 40.]]

i = np.vstack((a, b))
print(i)
# Example 2 - working


i = np.hstack((a, b))
print(i)<jupyter_output><empty_output><jupyter_text>Explanation about example<jupyter_code># Example 3 - breaking (to illustrate when it breaks)
i = np.hstack((A, b))
print(i)<jupyter_output><empty_output><jupyter_text>Explanation about example (why it breaks and how to fix it) Some closing comments about when to use this function.<jupyter_code>jovian.commit()<jupyter_output><empty_output><jupyter_text>Function 3 - ???Add some explanations<jupyter_code># Example 1 - working
a = np.array([[1, 3, 5, 7, 9, 11], 
              [2, 4, 6, 8, 10, 12]]) 
  
# horizontal splitting 
print("Splitting along horizontal axis into 2 parts:\n", np.hsplit(a, 2))<jupyter_output><empty_output><jupyter_text>Explanation about example<jupyter_code># Example 2 - working
# vertical splitting 
print("\nSplitting along vertical axis into 2 parts:\n", np.vsplit(a, 2))<jupyter_output><empty_output><jupyter_text>Explanation about example<jupyter_code># Example 3 - breaking (to illustrate when it breaks)
print("\nSplitting along vertical axis into 2 parts:\n", np.vsplit(a, 2,1))<jupyter_output><empty_output><jupyter_text>Explanation about example (why it breaks and how to fix it) Some closing comments about when to use this function.<jupyter_code>jovian.commit()<jupyter_output><empty_output><jupyter_text>Function 4 - np.datetime64Add some explanations<jupyter_code># Example 1 - working
# creating a date 
today = np.datetime64('2017-02-12') 
print("Date is:", today) 
print("Year is:", np.datetime64(today, 'Y'))<jupyter_output><empty_output><jupyter_text>Explanation about example<jupyter_code># Example 2 - working
# creating array of dates in a month 
dates = np.arange('2017-02', '2017-03', dtype='datetime64[D]') 
print("\nDates of February, 2017:\n", dates) 
print("Today is February:", today in dates)<jupyter_output><empty_output><jupyter_text>Explanation about example<jupyter_code># Example 3 - breaking (to illustrate when it breaks)
# arithmetic operation on dates 
dur = np.datetim64('2014-05-22') - np.datetime64('2016-05-22') 
print("\nNo. of days:", dur) 
print("No. of weeks:", np.timedelta64(dur, 'W'))<jupyter_output><empty_output><jupyter_text>Explanation about example (why it breaks and how to fix it) Some closing comments about when to use this function.<jupyter_code>jovian.commit()<jupyter_output><empty_output><jupyter_text>Function 5 - np.linalg.matrix_rankAdd some explanations<jupyter_code># Example 1 - working
  
A = np.array([[6, 1, 1], 
              [4, -2, 5], 
              [2, 8, 7]]) 
  
print("Rank of A:", np.linalg.matrix_rank(A)) 
  

  
print("\nInverse of A:\n", np.linalg.inv(A))<jupyter_output><empty_output><jupyter_text>Explanation about example<jupyter_code># Example 2 - working
print("\nMatrix A raised to power 3:\n", np.linalg.matrix_power(A, 3))<jupyter_output><empty_output><jupyter_text>Explanation about example<jupyter_code># Example 3 - breaking (to illustrate when it breaks)
print("\nMatrix A raised to power 3:\n", np.linalg.matrix_power(a, -3))<jupyter_output><empty_output><jupyter_text>Explanation about example (why it breaks and how to fix it) Some closing comments about when to use this function.<jupyter_code>jovian.commit()<jupyter_output><empty_output><jupyter_text>ConclusionSummarize what was covered in this notebook, and where to go next  Reference LinksProvide links to your references and other interesting articles about Numpy arrays:* Numpy official tutorial : https://numpy.org/doc/stable/user/quickstart.html* ...<jupyter_code>jovian.commit()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11658698050753953, 'fraction_numerical': 0.027951452739977935, 'mean_word_length': 5.120030007501875, 'pattern_counts': {'":': 0, '<': 97, '<?xml version=': 0, '>': 112, 'https://': 5, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '24', 'dir': 'jupyter-structured-clean-dedup', 'id': '510442', 'license': 'MIT', 'n_tokens_mistral': 2857, 'n_tokens_neox': 2633, 'n_words': 843, 'path': '.ipynb_checkpoints/Assignment-2-numpy-array-operations-checkpoint.ipynb', 'repo_name': 'Rey-commits/Jovian.AI', 'size': '8157'}