Saltar al contenido

cortar un array en el ejemplo de código de Python

Si te encuentras con algún detalle que no comprendes puedes dejarnos un comentario y trataremos de ayudarte lo mas rápido que podamos.

Ejemplo 1: Python corta un array

a[start:stop]# items start through stop-1
a[start:]# items start through the rest of the array
a[:stop]# items from the beginning through stop-1
a[:]# a copy of the whole array
Example:>>> a =[1,2,3,4,5,6,7,8]>>> a[1:4][2,3,4]

Ejemplo 2: python array rodaja

>>> a[1:4][2,3,4]

Ejemplo 3: array rebanar pitón

#slicing arrays:#generic sampling is done by #arr[start:end] -> where start is the starting index and end is ending idx>>>import numpy as np
>>> arr = np.array([1,2,3,4,5])>>>print(arr[1:5])#starting idx 1 to ending index 4[2345]#it will print from starting idx to ending idx-1#if you leave the ending index blank it will print all #from the starting index till end>>> arr = np.array([2,6,1,7,5])>>>print(arr[3:])[75]>>>print(arr[:3])#if you leave the starting index blank it will print from 0 index to the ending idx-1[261]>>>print(arr[:])[26175]#leaving both the index open will print the entire array.##########STEP slicing#########if you want to traverse by taking steps more than 1 #we use step slicing in that case#syntax for step slicing is : arr[start:end:step]>>> arr = np.array([2,6,1,7,5,10,43,21,100,29])>>>print(arr[1:8:2])#we have taken steps of two[671021]

Finalizando este artículo puedes encontrar las críticas de otros administradores, tú aún eres capaz insertar el tuyo si dominas el tema.

¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)



Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *