Skip to content

Commit b8da204

Browse files
committed
Added first 4 problems on NumPy Basic
1 parent 82852cf commit b8da204

File tree

2 files changed

+386
-22
lines changed

2 files changed

+386
-22
lines changed

02_NumPy/.ipynb_checkpoints/01_NumPy Basic [41 exercises with solution]-checkpoint.ipynb

+193-11
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,218 @@
2121
"cell_type": "markdown",
2222
"metadata": {},
2323
"source": [
24-
"### 1.Write a NumPy program to get the numpy version and show numpy build configuration."
24+
"## 1.Write a NumPy program to get the numpy version and show numpy build configuration."
2525
]
2626
},
2727
{
2828
"cell_type": "code",
29-
"execution_count": null,
29+
"execution_count": 5,
3030
"metadata": {},
31-
"outputs": [],
32-
"source": []
31+
"outputs": [
32+
{
33+
"name": "stdout",
34+
"output_type": "stream",
35+
"text": [
36+
"NumPy Version: 1.16.4\n",
37+
"\n",
38+
"Configuration:\n",
39+
"===============\n",
40+
"mkl_info:\n",
41+
" libraries = ['mkl_rt']\n",
42+
" library_dirs = ['C:/ProgramData/Anaconda3\\\\Library\\\\lib']\n",
43+
" define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]\n",
44+
" include_dirs = ['C:\\\\Program Files (x86)\\\\IntelSWTools\\\\compilers_and_libraries_2019.0.117\\\\windows\\\\mkl', 'C:\\\\Program Files (x86)\\\\IntelSWTools\\\\compilers_and_libraries_2019.0.117\\\\windows\\\\mkl\\\\include', 'C:\\\\Program Files (x86)\\\\IntelSWTools\\\\compilers_and_libraries_2019.0.117\\\\windows\\\\mkl\\\\lib', 'C:/ProgramData/Anaconda3\\\\Library\\\\include']\n",
45+
"blas_mkl_info:\n",
46+
" libraries = ['mkl_rt']\n",
47+
" library_dirs = ['C:/ProgramData/Anaconda3\\\\Library\\\\lib']\n",
48+
" define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]\n",
49+
" include_dirs = ['C:\\\\Program Files (x86)\\\\IntelSWTools\\\\compilers_and_libraries_2019.0.117\\\\windows\\\\mkl', 'C:\\\\Program Files (x86)\\\\IntelSWTools\\\\compilers_and_libraries_2019.0.117\\\\windows\\\\mkl\\\\include', 'C:\\\\Program Files (x86)\\\\IntelSWTools\\\\compilers_and_libraries_2019.0.117\\\\windows\\\\mkl\\\\lib', 'C:/ProgramData/Anaconda3\\\\Library\\\\include']\n",
50+
"blas_opt_info:\n",
51+
" libraries = ['mkl_rt']\n",
52+
" library_dirs = ['C:/ProgramData/Anaconda3\\\\Library\\\\lib']\n",
53+
" define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]\n",
54+
" include_dirs = ['C:\\\\Program Files (x86)\\\\IntelSWTools\\\\compilers_and_libraries_2019.0.117\\\\windows\\\\mkl', 'C:\\\\Program Files (x86)\\\\IntelSWTools\\\\compilers_and_libraries_2019.0.117\\\\windows\\\\mkl\\\\include', 'C:\\\\Program Files (x86)\\\\IntelSWTools\\\\compilers_and_libraries_2019.0.117\\\\windows\\\\mkl\\\\lib', 'C:/ProgramData/Anaconda3\\\\Library\\\\include']\n",
55+
"lapack_mkl_info:\n",
56+
" libraries = ['mkl_rt']\n",
57+
" library_dirs = ['C:/ProgramData/Anaconda3\\\\Library\\\\lib']\n",
58+
" define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]\n",
59+
" include_dirs = ['C:\\\\Program Files (x86)\\\\IntelSWTools\\\\compilers_and_libraries_2019.0.117\\\\windows\\\\mkl', 'C:\\\\Program Files (x86)\\\\IntelSWTools\\\\compilers_and_libraries_2019.0.117\\\\windows\\\\mkl\\\\include', 'C:\\\\Program Files (x86)\\\\IntelSWTools\\\\compilers_and_libraries_2019.0.117\\\\windows\\\\mkl\\\\lib', 'C:/ProgramData/Anaconda3\\\\Library\\\\include']\n",
60+
"lapack_opt_info:\n",
61+
" libraries = ['mkl_rt']\n",
62+
" library_dirs = ['C:/ProgramData/Anaconda3\\\\Library\\\\lib']\n",
63+
" define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]\n",
64+
" include_dirs = ['C:\\\\Program Files (x86)\\\\IntelSWTools\\\\compilers_and_libraries_2019.0.117\\\\windows\\\\mkl', 'C:\\\\Program Files (x86)\\\\IntelSWTools\\\\compilers_and_libraries_2019.0.117\\\\windows\\\\mkl\\\\include', 'C:\\\\Program Files (x86)\\\\IntelSWTools\\\\compilers_and_libraries_2019.0.117\\\\windows\\\\mkl\\\\lib', 'C:/ProgramData/Anaconda3\\\\Library\\\\include']\n",
65+
"None\n"
66+
]
67+
}
68+
],
69+
"source": [
70+
"import numpy as np\n",
71+
"\n",
72+
"print('NumPy Version:', np.__version__)\n",
73+
"print('\\nConfiguration:')\n",
74+
"print('='*15)\n",
75+
"print(np.show_config())"
76+
]
3377
},
3478
{
3579
"cell_type": "markdown",
3680
"metadata": {},
3781
"source": [
38-
"### 2. Write a NumPy program to get help on the add function."
82+
"## 2. Write a NumPy program to get help on the add function."
3983
]
4084
},
4185
{
4286
"cell_type": "code",
43-
"execution_count": null,
87+
"execution_count": 6,
4488
"metadata": {},
45-
"outputs": [],
46-
"source": []
89+
"outputs": [
90+
{
91+
"name": "stdout",
92+
"output_type": "stream",
93+
"text": [
94+
"add(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj])\n",
95+
"\n",
96+
"Add arguments element-wise.\n",
97+
"\n",
98+
"Parameters\n",
99+
"----------\n",
100+
"x1, x2 : array_like\n",
101+
" The arrays to be added. If ``x1.shape != x2.shape``, they must be\n",
102+
" broadcastable to a common shape (which may be the shape of one or\n",
103+
" the other).\n",
104+
"out : ndarray, None, or tuple of ndarray and None, optional\n",
105+
" A location into which the result is stored. If provided, it must have\n",
106+
" a shape that the inputs broadcast to. If not provided or `None`,\n",
107+
" a freshly-allocated array is returned. A tuple (possible only as a\n",
108+
" keyword argument) must have length equal to the number of outputs.\n",
109+
"where : array_like, optional\n",
110+
" Values of True indicate to calculate the ufunc at that position, values\n",
111+
" of False indicate to leave the value in the output alone.\n",
112+
"**kwargs\n",
113+
" For other keyword-only arguments, see the\n",
114+
" :ref:`ufunc docs <ufuncs.kwargs>`.\n",
115+
"\n",
116+
"Returns\n",
117+
"-------\n",
118+
"add : ndarray or scalar\n",
119+
" The sum of `x1` and `x2`, element-wise.\n",
120+
" This is a scalar if both `x1` and `x2` are scalars.\n",
121+
"\n",
122+
"Notes\n",
123+
"-----\n",
124+
"Equivalent to `x1` + `x2` in terms of array broadcasting.\n",
125+
"\n",
126+
"Examples\n",
127+
"--------\n",
128+
">>> np.add(1.0, 4.0)\n",
129+
"5.0\n",
130+
">>> x1 = np.arange(9.0).reshape((3, 3))\n",
131+
">>> x2 = np.arange(3.0)\n",
132+
">>> np.add(x1, x2)\n",
133+
"array([[ 0., 2., 4.],\n",
134+
" [ 3., 5., 7.],\n",
135+
" [ 6., 8., 10.]])\n",
136+
"None\n"
137+
]
138+
}
139+
],
140+
"source": [
141+
"print(np.info(np.add))"
142+
]
143+
},
144+
{
145+
"cell_type": "markdown",
146+
"metadata": {},
147+
"source": [
148+
"## 3. Write a NumPy program to test whether none of the elements of a given array is zero. "
149+
]
47150
},
48151
{
49152
"cell_type": "code",
50-
"execution_count": null,
153+
"execution_count": 14,
51154
"metadata": {},
52-
"outputs": [],
53-
"source": []
155+
"outputs": [
156+
{
157+
"name": "stdout",
158+
"output_type": "stream",
159+
"text": [
160+
"Checking if none of the array emements have 0:\n",
161+
"False\n",
162+
"Checking if at least one of the array emement is 0: \n",
163+
"True\n",
164+
"Checking if at least one of the array emement is 0: \n",
165+
"False\n"
166+
]
167+
}
168+
],
169+
"source": [
170+
"# Here we mainly checking whether all the elements are non zero or not\n",
171+
"\n",
172+
"import numpy as np\n",
173+
"\n",
174+
"arr1 = np.array([0, 1, 2, 3])\n",
175+
"print('Checking if none of the array emements have 0:') # returns 'False' if one of the array element is 0\n",
176+
"print(np.all(arr1))\n",
177+
"\n",
178+
"arr2 = np.array([1, 2, 3, 4])\n",
179+
"print('Checking if at least one of the array emement is 0: ') # returns 'True' if 0 is not present in the array emements\n",
180+
"print(np.all(arr2))\n",
181+
"\n",
182+
"arr3 = np.array([0, 0, 0, 0])\n",
183+
"print('Checking if at least one of the array emement is 0: ') # returns 'False' if one of the array element is 0\n",
184+
"print(np.all(arr3))"
185+
]
186+
},
187+
{
188+
"cell_type": "markdown",
189+
"metadata": {},
190+
"source": [
191+
"## 4. Write a NumPy program to test if any of the elements of a given array is non-zero."
192+
]
193+
},
194+
{
195+
"cell_type": "code",
196+
"execution_count": 18,
197+
"metadata": {},
198+
"outputs": [
199+
{
200+
"name": "stdout",
201+
"output_type": "stream",
202+
"text": [
203+
"Checking if none of the array emements have 0:\n",
204+
"True\n",
205+
"Checking if at least one of the array emement is 0: \n",
206+
"True\n",
207+
"Checking if at least one of the array emement is 0: \n",
208+
"False\n"
209+
]
210+
}
211+
],
212+
"source": [
213+
"# Here we mainly checking if any of the array elements contains other than '0'\n",
214+
"\n",
215+
"import numpy as np\n",
216+
"\n",
217+
"arr1 = np.array([0, 1, 2, 3])\n",
218+
"print('Checking if none of the array emements have 0:') # returns 'True' if one of the array element is not 0\n",
219+
"print(np.any(arr1))\n",
220+
"\n",
221+
"arr2 = np.array([1, 2, 3, 4])\n",
222+
"print('Checking if at least one of the array emement is 0: ') # returns 'True' if one of the array element is not 0\n",
223+
"print(np.any(arr2))\n",
224+
"\n",
225+
"arr3 = np.array([0, 0, 0, 0])\n",
226+
"print('Checking if at least one of the array emement is 0: ') # returns 'False' if all of the array element is 0\n",
227+
"print(np.any(arr3))"
228+
]
229+
},
230+
{
231+
"cell_type": "markdown",
232+
"metadata": {},
233+
"source": [
234+
"## 5. Write a NumPy program to test a given array element-wise for finiteness (not infinity or not a Number)."
235+
]
54236
},
55237
{
56238
"cell_type": "code",

0 commit comments

Comments
 (0)