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 54d65b2

Browse files
author
Amogh Singhal
authored
Add files via upload
1 parent 3ac19ea commit 54d65b2

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

‎bits_wilp/Ex2_Numpy_Q4.ipynb‎

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"id": "8ddc2bc7-042f-4552-92a3-f9047a132e56",
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": "30c3a8f2-797e-4427-9acd-0ea951421e92",
17+
"metadata": {},
18+
"source": [
19+
"### Determinant of a square array"
20+
]
21+
},
22+
{
23+
"cell_type": "code",
24+
"execution_count": 22,
25+
"id": "16a039d2-473c-4b23-8d08-108b0edae19b",
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: 3 4 2 2\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+
"[[3 4]\n",
44+
" [2 2]]\n",
45+
"\n",
46+
"The approx. determinant of the above square array is -2.0\n",
47+
"The absolute determinant of the above square array is -1.9999999999999998\n"
48+
]
49+
}
50+
],
51+
"source": [
52+
"arr_shape = int(input(\"Enter size of square array: \"))\n",
53+
"arr = list(map(int,input(\"Enter a square array in row-wise manner: \").split()))\n",
54+
"\n",
55+
"if len(arr) == arr_shape**2 :\n",
56+
" sq_arr = np.array(arr, dtype=int).reshape(arr_shape, arr_shape)\n",
57+
" print(\"\\nSUCCESS: Reshape operation completed\")\n",
58+
" print(f\"Given square array is\")\n",
59+
" print(sq_arr)\n",
60+
" print(f\"\\nThe approx. determinant of the above square array is {round(np.linalg.det(sq_arr),0)}\")\n",
61+
" print(f\"The absolute determinant of the above square array is {np.linalg.det(sq_arr)}\")\n",
62+
"else:\n",
63+
" print(f\"ERROR: Cannot reshape array of size {len(arr)} into {(arr_shape, arr_shape)}\")"
64+
]
65+
},
66+
{
67+
"cell_type": "code",
68+
"execution_count": null,
69+
"id": "35643ed3-5bfe-443a-adf0-df266ba9da72",
70+
"metadata": {},
71+
"outputs": [],
72+
"source": []
73+
}
74+
],
75+
"metadata": {
76+
"kernelspec": {
77+
"display_name": "Python 3",
78+
"language": "python",
79+
"name": "python3"
80+
},
81+
"language_info": {
82+
"codemirror_mode": {
83+
"name": "ipython",
84+
"version": 3
85+
},
86+
"file_extension": ".py",
87+
"mimetype": "text/x-python",
88+
"name": "python",
89+
"nbconvert_exporter": "python",
90+
"pygments_lexer": "ipython3",
91+
"version": "3.8.5"
92+
}
93+
},
94+
"nbformat": 4,
95+
"nbformat_minor": 5
96+
}

0 commit comments

Comments
(0)

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