October 2019
Beginner to intermediate
674 pages
16h 43m
English
Let's look at creation and selection in R:
>r_mat<- matrix(2:13,4,3)
>r_mat
[,1] [,2] [,3]
[1,] 2 6 10
[2,] 3 7 11
[3,] 4 8 12
[4,] 5 9 13
To select the first row, we write the following:
>r_mat[1,] [1] 2 6 10
To select the second column, we use the following command:
>r_mat[,2] [1] 6 7 8 9
Let's now look at NumPy array creation and selection:
In [60]: a=np.array(range(2,6))
b=np.array(range(6,10))
c=np.array(range(10,14))
In [66]: np_ar=np.column_stack([a,b,c])
np_ar
Out[66]: array([[ 2, 6, 10],
[ 3, 7, 11],
[ 4, 8, 12],
[ 5, 9, 13]])
To select the first row, we use the following command:
In [79]: np_ar[0,]
Out[79]: array([ 2, 6, 10])
Read now
Unlock full access