Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 618910b

Browse files
author
Amogh Singhal
authored
Add files via upload
1 parent 54d65b2 commit 618910b

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

‎bits_wilp/Ex2_Numpy_Q5.ipynb‎

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"id": "678ce984-841d-49bd-b2c5-8586aaed05b2",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"import numpy as np\n",
11+
"import pandas as pd"
12+
]
13+
},
14+
{
15+
"cell_type": "markdown",
16+
"id": "c8866271-04d5-4bd6-9916-f55bc5889968",
17+
"metadata": {},
18+
"source": [
19+
"### Eigenvalues and Eigenvectors of a square array"
20+
]
21+
},
22+
{
23+
"cell_type": "code",
24+
"execution_count": 3,
25+
"id": "346bcf67-e5be-49d2-8e22-31d87ed416cd",
26+
"metadata": {},
27+
"outputs": [
28+
{
29+
"name": "stdin",
30+
"output_type": "stream",
31+
"text": [
32+
"Enter size of square array: 2\n",
33+
"Enter a square array in row-wise manner: 1 2 2 1\n"
34+
]
35+
},
36+
{
37+
"name": "stdout",
38+
"output_type": "stream",
39+
"text": [
40+
"\n",
41+
"SUCCESS: Reshape operation completed\n",
42+
"Given square array is\n",
43+
"[[1 2]\n",
44+
" [2 1]]\n",
45+
"The eigenvalues of the above square array is\n",
46+
"[ 3. -1.]\n",
47+
"The eigenvectors of the above square array is\n",
48+
"[[ 0.70710678 -0.70710678]\n",
49+
" [ 0.70710678 0.70710678]]\n"
50+
]
51+
}
52+
],
53+
"source": [
54+
"arr_shape = int(input(\"Enter size of square array: \"))\n",
55+
"arr = list(map(int,input(\"Enter a square array in row-wise manner: \").split()))\n",
56+
"\n",
57+
"if len(arr) == arr_shape**2 :\n",
58+
" sq_arr = np.array(arr, dtype=int).reshape(arr_shape, arr_shape)\n",
59+
" print(\"\\nSUCCESS: Reshape operation completed\")\n",
60+
" print(f\"Given square array is\")\n",
61+
" print(sq_arr)\n",
62+
" \n",
63+
" eig_val, eig_vec = np.linalg.eig(sq_arr)\n",
64+
" print(\"The eigenvalues of the above square array is\")\n",
65+
" print(eig_val)\n",
66+
" print(\"The eigenvectors of the above square array is\")\n",
67+
" print(eig_vec)\n",
68+
"else:\n",
69+
" print(f\"ERROR: Cannot reshape array of size {len(arr)} into {(arr_shape, arr_shape)}\")"
70+
]
71+
},
72+
{
73+
"cell_type": "code",
74+
"execution_count": null,
75+
"id": "897a5000-e52d-4a07-afc1-2b722ec423e5",
76+
"metadata": {},
77+
"outputs": [],
78+
"source": []
79+
}
80+
],
81+
"metadata": {
82+
"kernelspec": {
83+
"display_name": "Python 3",
84+
"language": "python",
85+
"name": "python3"
86+
},
87+
"language_info": {
88+
"codemirror_mode": {
89+
"name": "ipython",
90+
"version": 3
91+
},
92+
"file_extension": ".py",
93+
"mimetype": "text/x-python",
94+
"name": "python",
95+
"nbconvert_exporter": "python",
96+
"pygments_lexer": "ipython3",
97+
"version": "3.8.5"
98+
}
99+
},
100+
"nbformat": 4,
101+
"nbformat_minor": 5
102+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /