Click on New in the upper right-hand side of the screen, then select Python 3 (pykernel) to
Question:
Click on New in the upper right-hand side of the screen, then select Python 3 (pykernel) to open up a new Jupyter Notebook file. Copy the code snippets below into the In window and run the code. Copy the results below each code snippet and briefly explain the actions the code performed. Click on the plus sign, to open a new In window for each code snippet.
a) Creating and reshaping arrays
1)
import numpy as np
a_arr = np.array((1, 2, 3, 4))
a_arr
2)
b_arr = np.arange(0, 16)
b_arr
3)
c_arr = b_arr.reshape(4, 4)
c_arr
4)
d_arr = np.arange(10, 26).reshape(4, 4)
d_arr
b) Accessing and altering elements within an array,
1)
a_arr[2]
2)
a_arr[2] = 5
a_arr
3)
a_arr.dtype
a_arr.ndim
a_arr.shape
a_arr.size
c) Aggregate functions
1)
d_arr.sum()
d_arr.min()
d_arr.max()
d_arr.mean()
d_arr.median()
d_arr.std()
d) Arithmetic Operations, Matrix Operations, Broadcasting, and Comparisons
1) Arithmetic operations
a_arr + 5
e_arr = c_arr + d_arr
e_arr
e_arr = c_arr - d_arr
e_arr
e_arr = c_arr * d_arr
e_arr
e_arr = d_arr / c_arr
e_arr
Question:
• What is the problem with the statement above
e_arr = np.sqrt(d_arr)
e_arr
2) Matric operations
f_arr = np.dot(c_arr, d_arr)
f_arr
3) Broadcasting
g_arr = a_arr * c_arr
g_arr
4) Comparisons
c_arr< 6
c_arr = c_arr * 10
c_arr < f_arr
e) Joining, Splitting, and Splicing Arrays
1) Joining
w_arr = np.vstack((c_arr, f_arr))
w_arr
w_arr = np.hstack((c_arr, f_arr))
w_arr
2) Splitting
x_arr = np.hsplit(c_arr, 2)
x_arr
x_arr = np.vsplit(c_arr, 2)
x_arr
3) Slicing
One dimensional array
b_arr[2:10:3]
b_arr[:10:3]
b_arr[::3]
Two-dimensional array
c_arr[0:1, :]
c_arr[0:1, 1:3]
c_arr[1:3, 1:3]
f) Saving and Loading Arrays
1) Saving
np.save('c_arr.npy',c_arr)
2) Loading
np.load('c_arr.npy')
Integrated Accounting
ISBN: 978-1285462721
8th edition
Authors: Dale A. Klooster, Warren Allen, Glenn Owen