Search this site
Embedded Files
AIMD GPDS Courses
  • Home
  • Courses
  • Contact
AIMD GPDS Courses
  • Home
  • Courses
  • Contact
  • More
    • Home
    • Courses
    • Contact

日本語  ❯

Lesson 5    ❮    Lesson List    ❮    Top Page

5.1 NumPy Arrays      

❯  5.2  Index and Reshape      

5.3 Universal Functions     

5.4 Join, Split, and Transpose

5.5 Search and Filter      

⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
EXPECTED COMPLETION TIME
❲▹❳  Video   4m 44s
☷  Interactive readings   5m
✑  Practice 5.2 (G Colab)   15m

Accessing Array Elements

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.

Slicing Multidimensional Arrays

Again, slicing ndarray is very similar to slicing a list. We pass slice like this [start:end] or [start:end:step]

Reshaping Arrays

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.

Reshaping with Unknown Dimension

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.

©2023. All rights reserved.  Samy Baladram,
Graduate Program in Data Science - GSIS - Tohoku University
Google Sites
Report abuse
Page details
Page updated
Google Sites
Report abuse