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 3ac19ea

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

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

‎bits_wilp/Ex2_Numpy_Q3.ipynb‎

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"id": "3b75f73e-6d1b-4a9e-935d-4a3d229bcc6a",
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": "65b9b866-0960-40d1-8deb-4ebe1261d420",
17+
"metadata": {},
18+
"source": [
19+
"### Cross Product of two given vectors"
20+
]
21+
},
22+
{
23+
"cell_type": "code",
24+
"execution_count": 2,
25+
"id": "1a98a54e-7a31-4575-84ec-c72c4aadb8a4",
26+
"metadata": {},
27+
"outputs": [],
28+
"source": [
29+
"# Function to take input array from user\n",
30+
"def np_array_frm_input(prompt):\n",
31+
" try:\n",
32+
" arr = list(map(int, input(prompt).split()))\n",
33+
" np_array = np.array(arr, dtype=int)\n",
34+
" except ValueError as e:\n",
35+
" np_array = None\n",
36+
" print(\"ERROR: Please enter only integers !!!\")\n",
37+
" print(e)\n",
38+
" return np_array"
39+
]
40+
},
41+
{
42+
"cell_type": "code",
43+
"execution_count": 4,
44+
"id": "f540a81d-f8e5-44c1-a280-ac96211ea7c4",
45+
"metadata": {},
46+
"outputs": [
47+
{
48+
"name": "stdin",
49+
"output_type": "stream",
50+
"text": [
51+
"Enter the first integer vector... 3\n",
52+
"Enter the second integer vector... 4 5\n"
53+
]
54+
},
55+
{
56+
"name": "stdout",
57+
"output_type": "stream",
58+
"text": [
59+
"ERROR: Vectors must be 2D pr 3D for computing cross-product !!!\n",
60+
"incompatible dimensions for cross product\n",
61+
"(dimension must be 2 or 3)\n"
62+
]
63+
}
64+
],
65+
"source": [
66+
"try:\n",
67+
" vec1 = np_array_frm_input(\"Enter the first integer vector...\")\n",
68+
" vec2 = np_array_frm_input(\"Enter the second integer vector...\")\n",
69+
" print(f\"The cross product between {vec1} and {vec2} is {np.cross(vec1, vec2)}\")\n",
70+
"except ValueError as e:\n",
71+
" print(\"ERROR: Vectors must be 2D pr 3D for computing cross-product !!!\")\n",
72+
" print(e)"
73+
]
74+
},
75+
{
76+
"cell_type": "code",
77+
"execution_count": null,
78+
"id": "a7c915f7-e509-46e9-843a-c891fd2e64a3",
79+
"metadata": {},
80+
"outputs": [],
81+
"source": []
82+
}
83+
],
84+
"metadata": {
85+
"kernelspec": {
86+
"display_name": "Python 3",
87+
"language": "python",
88+
"name": "python3"
89+
},
90+
"language_info": {
91+
"codemirror_mode": {
92+
"name": "ipython",
93+
"version": 3
94+
},
95+
"file_extension": ".py",
96+
"mimetype": "text/x-python",
97+
"name": "python",
98+
"nbconvert_exporter": "python",
99+
"pygments_lexer": "ipython3",
100+
"version": "3.8.5"
101+
}
102+
},
103+
"nbformat": 4,
104+
"nbformat_minor": 5
105+
}

0 commit comments

Comments
(0)

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