JupyterLab is the latest web-based interactive development environment for notebooks, code, and data. Its flexible interface allows users to configure and arrange workflows in data science, scientific computing, computational journalism, and machine learning. A modular design invites extensions to expand and enrich functionality.
instructions of using JupyterLab
NumPy is a commonly used Python data analysis package that is used to speed up the workflow, and interface with other packages in Pythons ecosystem.
In a NumPy array, the number of dimensions is called the rank, and each dimension is called an axis. So the rows are the first axis, and the columns are the second axis.
We can create a NumPy array using the numpy.array function. If we pass in a list of lists, it will automatically create a NumPy array with the same number of rows and columns
imoprt numpy as np
–> this will create a 3 rows 4 columns array with all elements = 0
empty_array = np.zeros((3,4))
np.zeros(5)
array([ 0., 0., 0., 0., 0.])
np.zeros((2, 1))
array([[ 0.],
[ 0.]])
s = (2,2)
np.zeros(s)
array([[ 0., 0.],
[ 0., 0.]])
–> Generate a 2 x 4 array of ints between 0 and 4, inclusive:
np.random.randint(5, size=(2, 4))
array([[4, 0, 2, 1],
[3, 2, 2, 0]])
–> We can use it to read in our initial data on red wines.
example: -Use the genfromtxt function to read in the winequality-red.csv file. -Specify the keyword argument delimiter=”;” so that the fields are parsed properly. -Specify the keyword argument skip_header=1 so that the header row is skipped.
wines = np.genfromtxt("winequality-red.csv", delimiter=";", skip_header=1)
looks like this
11.200
0.280
0.560
1.900
0.075
17.000
60.000
0.998
3.160
0.580
9.800
6.000
np.random.rand(3)
list of lists of lists.
NumPy is written in a programming language called C, which stores data differently than the Python data types.
–> to convert an array to a different type. copies and returns new array with specified data type
–> create NumPy dtype objects like numpy.int32:
regular operations can be applied to numpy arrays
np.transpose(wines).shape
–> rows become columns, and vice versa
-using numpy.ravel
array_one = np.array(
[
[1, 2, 3, 4],
[5, 6, 7, 8]
]
)
array_one.ravel()
output –> array([1, 2, 3, 4, 5, 6, 7, 8])
-using numpy.reshape
wines[1,:].reshape((2,6))
–> will turn the second row of wines into a 2-dimensional array with 2 rows and 6 columns: