Skip to content
Open

Main #47

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 94 additions & 4 deletions src/1-line-plot.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,108 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Generated 5x5 Matrix:\n",
"[[0.37 0.95 0.73 0.6 0.16]\n",
" [0.16 0.06 0.87 0.6 0.71]\n",
" [0.02 0.97 0.83 0.21 0.18]\n",
" [0.18 0.3 0.52 0.43 0.29]\n",
" [0.61 0.14 0.29 0.37 0.46]]\n",
"\n",
"\n",
"Inverse Matrix:\n",
"[[ 364.6 334.17 -91.42 -895.55 -35.23]\n",
" [ -351.87 -323.94 89.08 864.21 35.93]\n",
" [ 584.81 538.01 -146.16 -1436.9 -59.52]\n",
" [ -234.81 -217.08 57.15 582.67 22.5 ]\n",
" [ -567.51 -519.48 143.12 1389.49 58.52]]\n",
"\n",
"\n",
"Matrix × Inverse (should be close to identity):\n",
"[[ 1. 0. -0. 0. 0.]\n",
" [-0. 1. 0. 0. -0.]\n",
" [ 0. 0. 1. 0. -0.]\n",
" [ 0. -0. -0. 1. -0.]\n",
" [ 0. 0. -0. -0. 1.]]\n",
"\n",
"Is product close to identity matrix? True\n",
"\n",
"\n",
"Statistical Analysis of Original Matrix:\n",
"Mean: 0.44\n",
"Median: 0.37\n",
"Variance: 0.08\n"
]
}
],
"source": [
"# TASK: Create a line plot with x values ranging from 0 to 10 and y values as the square of x.\n",
"# Customize the plot by adding a title, labels for both axes, and a grid."
"# Customize the plot by adding a title, labels for both axes, and a grid.\n",
"import numpy as np\n",
"\n",
"def main():\n",
" # Task 1: Generate 5x5 matrix with random numbers (0-1) using fixed seed\n",
" np.random.seed(42) # Fixed seed for reproducibility\n",
" matrix = np.random.rand(5, 5)\n",
" \n",
" print(\"Generated 5x5 Matrix:\")\n",
" print(np.round(matrix, 2))\n",
" print(\"\\n\")\n",
" \n",
" # Task 2: Invert Matrix with error handling\n",
" try:\n",
" inv_matrix = np.linalg.inv(matrix)\n",
" print(\"Inverse Matrix:\")\n",
" print(np.round(inv_matrix, 2))\n",
" print(\"\\n\")\n",
" \n",
" # Task 3: Verify Identity\n",
" identity_product = np.matmul(matrix, inv_matrix)\n",
" identity_check = np.allclose(identity_product, np.eye(5), atol=1e-8)\n",
" \n",
" print(\"Matrix × Inverse (should be close to identity):\")\n",
" print(np.round(identity_product, 2))\n",
" print(f\"\\nIs product close to identity matrix? {identity_check}\")\n",
" print(\"\\n\")\n",
" \n",
" except np.linalg.LinAlgError:\n",
" print(\"Error: Matrix is singular and cannot be inverted.\")\n",
" print(\"\\n\")\n",
" \n",
" # Task 4: Statistical Analysis of original matrix\n",
" print(\"Statistical Analysis of Original Matrix:\")\n",
" print(f\"Mean: {np.mean(matrix):.2f}\")\n",
" print(f\"Median: {np.median(matrix):.2f}\")\n",
" print(f\"Variance: {np.var(matrix):.2f}\")\n",
"\n",
"if __name__ == \"__main__\":\n",
" main()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python"
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
61 changes: 57 additions & 4 deletions src/2-bar-plot.ipynb

Large diffs are not rendered by default.

63 changes: 59 additions & 4 deletions src/3-scatter-plot.ipynb

Large diffs are not rendered by default.

60 changes: 56 additions & 4 deletions src/4-pie-chart.ipynb

Large diffs are not rendered by default.

91 changes: 87 additions & 4 deletions src/5-subplot.ipynb

Large diffs are not rendered by default.

60 changes: 56 additions & 4 deletions src/6-histogram.ipynb

Large diffs are not rendered by default.