Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Get One Dimensional Array Using Slice and Only Positive Indexes | Indexing and Slicing
NumPy in a Nutshell

book
Get One Dimensional Array Using Slice and Only Positive Indexes

Let's examine the syntax of slicing: array[start:end:step], where:

  • start is the index from which the slicing begins;

  • end is the index at which the slicing concludes (note that this index is not included);

  • step is the parameter that specifies the intervals between the indices.

Tarea

Swipe to start coding

Consider the following array: [11, 5, 87, 1, 44, 11, 6, 0, -5].
You need to obtain the following array: [87, 11, -5].
Use a slice with ONLY NON-NEGATIVE start, end, and step values.

Solución

import numpy as np

arr = np.array([11, 5, 87, 1, 44, 11, 6, 0, -5])

# 1. Get [87, 11, -5] using slicing with positive indexing
print(arr[2:9:3])

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 3. Capítulo 7
import numpy as np

arr = np.array([11, 5, 87, 1, 44, 11, 6, 0, -5])

# 1. Get [87, 11, -5] using slicing with positive indexes
print(arr[___:___:___])

Pregunte a AI

expand
ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

some-alt