Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Reshaping | Important Functions
NumPy in a Nutshell
course content

Contenido del Curso

NumPy in a Nutshell

NumPy in a Nutshell

1. Getting Started with NumPy
2. Dimensions in Arrays
3. Indexing and Slicing
4. Important Functions

Reshaping

Sometimes situations arise when we need to somehow change our array, for example, change the size of the array or go from an array of one dimension to an array of another dimension, but with the same data that was originally used. But it is not always convenient to recreate the array from scratch, so some functions modify the array as we need it.

Let's have a look at some of them:

  • np.reshape() - this function changes the shape of an N-dimensional array while maintaining the same total number of elements;
  • np.transpose() - this function transposes the array, essentially swapping its axes;
  • np.concatenate() - this function creates a new array by appending arrays one after another along the specified axis;
  • np.resize() - this function is used to resize an array, creating a copy of the original array with the specified size.

Reshape one-dimensional array into a two-dimensional array:

123456
import numpy as np array = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) new_array = array.reshape(4, 3) print(new_array)
copy

Reshape one-dimensional into a three-dimensional array:

123456
import numpy as np array = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) new_array = array.reshape(2, 3, 2) print(new_array)
copy

Tarea

Consider the following array: [11, 56, 78, 45, 1, 5]. You should obtain the following array: [[11, 56], [78, 45], [1, 5]].

Please use the .reshape() method.

Tarea

Consider the following array: [11, 56, 78, 45, 1, 5]. You should obtain the following array: [[11, 56], [78, 45], [1, 5]].

Please use the .reshape() method.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Sección 4. Capítulo 1
toggle bottom row

Reshaping

Sometimes situations arise when we need to somehow change our array, for example, change the size of the array or go from an array of one dimension to an array of another dimension, but with the same data that was originally used. But it is not always convenient to recreate the array from scratch, so some functions modify the array as we need it.

Let's have a look at some of them:

  • np.reshape() - this function changes the shape of an N-dimensional array while maintaining the same total number of elements;
  • np.transpose() - this function transposes the array, essentially swapping its axes;
  • np.concatenate() - this function creates a new array by appending arrays one after another along the specified axis;
  • np.resize() - this function is used to resize an array, creating a copy of the original array with the specified size.

Reshape one-dimensional array into a two-dimensional array:

123456
import numpy as np array = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) new_array = array.reshape(4, 3) print(new_array)
copy

Reshape one-dimensional into a three-dimensional array:

123456
import numpy as np array = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) new_array = array.reshape(2, 3, 2) print(new_array)
copy

Tarea

Consider the following array: [11, 56, 78, 45, 1, 5]. You should obtain the following array: [[11, 56], [78, 45], [1, 5]].

Please use the .reshape() method.

Tarea

Consider the following array: [11, 56, 78, 45, 1, 5]. You should obtain the following array: [[11, 56], [78, 45], [1, 5]].

Please use the .reshape() method.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Sección 4. Capítulo 1
toggle bottom row

Reshaping

Sometimes situations arise when we need to somehow change our array, for example, change the size of the array or go from an array of one dimension to an array of another dimension, but with the same data that was originally used. But it is not always convenient to recreate the array from scratch, so some functions modify the array as we need it.

Let's have a look at some of them:

  • np.reshape() - this function changes the shape of an N-dimensional array while maintaining the same total number of elements;
  • np.transpose() - this function transposes the array, essentially swapping its axes;
  • np.concatenate() - this function creates a new array by appending arrays one after another along the specified axis;
  • np.resize() - this function is used to resize an array, creating a copy of the original array with the specified size.

Reshape one-dimensional array into a two-dimensional array:

123456
import numpy as np array = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) new_array = array.reshape(4, 3) print(new_array)
copy

Reshape one-dimensional into a three-dimensional array:

123456
import numpy as np array = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) new_array = array.reshape(2, 3, 2) print(new_array)
copy

Tarea

Consider the following array: [11, 56, 78, 45, 1, 5]. You should obtain the following array: [[11, 56], [78, 45], [1, 5]].

Please use the .reshape() method.

Tarea

Consider the following array: [11, 56, 78, 45, 1, 5]. You should obtain the following array: [[11, 56], [78, 45], [1, 5]].

Please use the .reshape() method.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Sometimes situations arise when we need to somehow change our array, for example, change the size of the array or go from an array of one dimension to an array of another dimension, but with the same data that was originally used. But it is not always convenient to recreate the array from scratch, so some functions modify the array as we need it.

Let's have a look at some of them:

  • np.reshape() - this function changes the shape of an N-dimensional array while maintaining the same total number of elements;
  • np.transpose() - this function transposes the array, essentially swapping its axes;
  • np.concatenate() - this function creates a new array by appending arrays one after another along the specified axis;
  • np.resize() - this function is used to resize an array, creating a copy of the original array with the specified size.

Reshape one-dimensional array into a two-dimensional array:

123456
import numpy as np array = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) new_array = array.reshape(4, 3) print(new_array)
copy

Reshape one-dimensional into a three-dimensional array:

123456
import numpy as np array = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) new_array = array.reshape(2, 3, 2) print(new_array)
copy

Tarea

Consider the following array: [11, 56, 78, 45, 1, 5]. You should obtain the following array: [[11, 56], [78, 45], [1, 5]].

Please use the .reshape() method.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
Sección 4. Capítulo 1
Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
We're sorry to hear that something went wrong. What happened?
some-alt