Lesson 5 ❮ Lesson List ❮ Top Page
❯ 5.2 Index and Reshape
5.4 Join, Split, and Transpose
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
EXPECTED COMPLETION TIME
❲▹❳ Video 4m 44s
☷ Interactive readings 5m
✑ Practice 5.2 (G Colab) 15m
You can access an array element by referring to its index number just like in list.
To access elements from 2-D arrays, you can use comma separated integers representing the dimension and the index of the element.
Again, slicing ndarray is very similar to slicing a list. We pass slice like this [start:end] or [start:end:step]
Reshaping means changing the shape of the given array. By reshaping an array we can add or remove dimensions or change the number of elements in each dimension.
In order to reshape a numpy array,
array.reshape(shape)
return an array of new shape from array.
It is allowed to have one "unknown" dimension. Meaning that not all the dimensions in the reshape method has to be specified.
Pass -1 as the value, and NumPy will calculate this number for you.
(Note: In this example, you cannot reshape with 4 or 5 columns since 6 is not divisible by 4 or 5)
Reshaping using (-1,1) value is particularly useful to convert a row array into a column array.