Open workspace
Tools 1.2Code walkthrough7 parts

Shape, dtype and Reshaping

Read any array's shape and dtype, and reshape without copying.

In this lesson7 parts

  1. 01Loading an array, and reading its shape
  2. 02Reshaping to a grid: shape, ndim, size and len
  3. 03Reshape changes the reading, not the buffer
  4. 04dtype, itemsize and nbytes
  5. 05Fixed width: int8, astype and silent wraparound
  6. 06Creating arrays without data: zeros, ones, arange and linspace
  7. 07Recap and your challenge

Quiz 5 questions

Answer each one in your head, or on paper, before you check it. Getting one wrong here is how the lesson sticks.

  1. 01

    sales holds 2,920 revenue values in one flat line. What does sales.reshape(-1, 8).shape give?

  2. 02

    What does np.zeros(3) hold — integers or decimal numbers?

  3. 03

    How many values does np.arange(0, 1, 0.1) give you?

  4. 04

    Our units column runs from 57 to 564. You convert it with units.astype(np.int8) to save memory. What happens?

  5. 05

    revenue_grid has shape (365, 8) and dtype('float64'). What is revenue_grid.nbytes, and why?