Skip to content

Commit 2066f00

Browse files
author
Amogh Singhal
authored
Add files via upload
1 parent c7c889b commit 2066f00

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

bits_wilp/Ex2_Numpy_Q1.ipynb

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"id": "846061b9-4829-48a0-a2be-dae592b8f95a",
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": "0901b4de-dd28-4433-ac7b-8db0d9a0f995",
17+
"metadata": {},
18+
"source": [
19+
"### Size of Numpy array in bytes"
20+
]
21+
},
22+
{
23+
"cell_type": "code",
24+
"execution_count": 2,
25+
"id": "2cec0596-d393-479b-bf67-3deddec0ea9e",
26+
"metadata": {},
27+
"outputs": [
28+
{
29+
"name": "stdin",
30+
"output_type": "stream",
31+
"text": [
32+
"Enter integers seperated by space. Press ENTER to end... 34 23 67 89\n"
33+
]
34+
},
35+
{
36+
"name": "stdout",
37+
"output_type": "stream",
38+
"text": [
39+
"Given sequence is\n",
40+
"[34, 23, 67, 89]\n",
41+
"Number of elements in the numpy array: 4\n",
42+
"Total bytes consumed by the numpy array: 16\n",
43+
"Size in bytes of each element in the numpy array: 4\n"
44+
]
45+
}
46+
],
47+
"source": [
48+
"try:\n",
49+
" # feed integer array from user\n",
50+
" arr = list(map(int, input(\"Enter integers seperated by space. Press ENTER to end...\").split()))\n",
51+
" print(\"Given sequence is\")\n",
52+
" print(arr)\n",
53+
" # convert Python array to Numpy array\n",
54+
" np_array = np.array(arr, dtype=int)\n",
55+
" print(f\"Number of elements in the numpy array: {np_array.size}\")\n",
56+
" print(f\"Total bytes consumed by the numpy array: {np_array.nbytes}\")\n",
57+
" print(f\"Size in bytes of each element in the numpy array: {(np_array.nbytes)//(np_array.size)}\")\n",
58+
"except ValueError as e:\n",
59+
" print(\"ERROR: Please enter only integers !!!\")\n",
60+
" print(e)"
61+
]
62+
},
63+
{
64+
"cell_type": "code",
65+
"execution_count": null,
66+
"id": "3e18b28b-796a-428f-96f7-cd530fd0cfd1",
67+
"metadata": {},
68+
"outputs": [],
69+
"source": []
70+
}
71+
],
72+
"metadata": {
73+
"kernelspec": {
74+
"display_name": "Python 3",
75+
"language": "python",
76+
"name": "python3"
77+
},
78+
"language_info": {
79+
"codemirror_mode": {
80+
"name": "ipython",
81+
"version": 3
82+
},
83+
"file_extension": ".py",
84+
"mimetype": "text/x-python",
85+
"name": "python",
86+
"nbconvert_exporter": "python",
87+
"pygments_lexer": "ipython3",
88+
"version": "3.8.5"
89+
}
90+
},
91+
"nbformat": 4,
92+
"nbformat_minor": 5
93+
}

0 commit comments

Comments
 (0)