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

# + [markdown] id="view-in-github" colab_type="text"
# <a href="https://colab.research.google.com/github/VishalDalwadi/027_VishalDalwadi/blob/main/Lab_01_Linear_Algebra.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>

# + colab={"base_uri": "https://localhost:8080/"} id="Wytm29pC8GxP" outputId="e5bb36ab-cbc7-4b90-aca3-21da8da2b9f5"
from google.colab import drive
drive.mount("/content/drive")

# + id="NLhsXKXm8wDd"
import numpy as np
import pandas as pd

# + colab={"base_uri": "https://localhost:8080/"} id="YrMwOlBi9RHU" outputId="48a672d8-6f70-4213-dd54-e0c58806058f"
# two matrices
array1 = np.array([[1, 2, 3],[4, 5, 6]])
array2 = np.array([[7, 10],[8, 11],[9, 12]])
print(array1)
print(array2)

# + colab={"base_uri": "https://localhost:8080/"} id="0G4ztctz9iph" outputId="0ae5a971-fccd-45a6-a4a0-9e7f3758d48d"
#randomly initialize array
array = np.random.rand(3, 4)
print(array)

# + colab={"base_uri": "https://localhost:8080/"} id="pGD17M4e9t9Z" outputId="f4137f08-fb4f-4edf-d986-55c0015c8932"
# perform matrix multiplication
mul = np.dot(array1, array2)
print(mul)

# + colab={"base_uri": "https://localhost:8080/"} id="mCT8XbnA926h" outputId="e5f7f9a7-4224-44d5-bbb7-3604f07e667a"
# perform element wise matrix multiplication
res = [[0 for x in range(len(array1))] for y in range(len(array2[0]))]

for i in range(len(array1)): 
  for j in range(len(array2[0])): 
    for k in range(len(array2)): 
      res[i][j] += array1[i][k] * array2[k][j]
 
print (res) 

# + colab={"base_uri": "https://localhost:8080/"} id="pmbcqzXg-SsJ" outputId="0fe830aa-5225-48cc-b35f-2dfff1922f62"
# mean of first matrix
mean = np.mean(array1)
print(mean)

# + id="AOi7uQv-SdIm"
main_data = pd.read_csv("/content/drive/MyDrive/ML_Labs/Lab1/mtcars.csv")

# + colab={"base_uri": "https://localhost:8080/"} id="WQvwWW_ATFPq" outputId="e8c32a62-1659-4022-a16a-d843196cd22a"
del main_data['model']
# meancenter
meancenter = main_data.apply(lambda e: e - e.mean())
print(meancenter.head())


# + id="yLR1NUfNUDvX"


StarcoderdataJupyterScriptsDedupFiltered