Numpy Basic (Part 2)
Shape and Reshape¶
Something really useful is be able to change or create an array in a specific shape, we will start with the same array that before:
Find the shape¶
now we can use shape
to find what shape our array has in this moment
How to reshape
¶
we can use the function reshape
to change the previous vector
Syntax
we need to reshape to values that make sense, in this case 2 rows and 5 columns does, because \(2*5 = 10\)
if i try to create a shape that is not correct i will get a valueError
exception, like here
Indexing¶
it is important to be able to get back rows, columns or slice of the matrix we create, in this case we enter to scope of indexing.
Find a single digit in the matrix¶
let say that i want to get the element in row = 0
and col = 1
Syntax
we don't need to define the variables 'row' and 'col' we can simply
How to slice a matrix¶
let say that we want
1. Get all the values in a row or column we want to get all the values in the row 1
Syntax
now for the column
we can change the shape of the new array
2. Get all the values from n rows and m columns We want to get back part of the original matrix
we can replace part of the matrix as well