Saltar al contenido principal
Library homepage
 

Text Color

Text Size

 

Margin Size

 

Font Type

Enable Dyslexic Font
LibreTexts Español

42.4: Indexación avanzada de Python

( \newcommand{\kernel}{\mathrm{null}\,}\)

Este es un poco largo y revisa parte de la información del último video. Sin embargo, me gusta mucho usar imágenes como una forma de hablar sobre la indexación de matrices y matrices en Numpy.

Enlace directo al video de Youtube.

Login with LibreOne to run this code cell interactively.

If you have already signed in, please refresh the page.

from IPython.display import YouTubeVideo
YouTubeVideo("XSyiafkKerQ",width=640,height=360, cc_load_policy=True)
from IPython.display import YouTubeVideo
YouTubeVideo("XSyiafkKerQ",width=640,height=360, cc_load_policy=True)

Login with LibreOne to run this code cell interactively.

If you have already signed in, please refresh the page.

%matplotlib inline
import matplotlib.pylab as plt
import numpy as np
import imageio

#from urllib.request import urlopen, urlretrieve
from imageio import imsave

url = 'https://res.cloudinary.com/miles-extranet-dev/image/upload/ar_16:9,c_fill,w_1000,g_face,q_50/Michigan/migration_photos/G21696/G21696-msubeaumonttower01.jpg'
im = imageio.imread(url)

im[10,10,0] = 255
im[10,10,1] = 255
im[10,10,2] = 255

#Show the image
plt.imshow(im);
%matplotlib inline
import matplotlib.pylab as plt
import numpy as np
import imageio

#from urllib.request import urlopen, urlretrieve
from imageio import imsave

url = 'https://res.cloudinary.com/miles-extranet-dev/image/upload/ar_16:9,c_fill,w_1000,g_face,q_50/Michigan/migration_photos/G21696/G21696-msubeaumonttower01.jpg'
im = imageio.imread(url)

im[10,10,0] = 255
im[10,10,1] = 255
im[10,10,2] = 255

#Show the image
plt.imshow(im);

Login with LibreOne to run this code cell interactively.

If you have already signed in, please refresh the page.

im[20,20,:] = 255
plt.imshow(im)
im[20,20,:] = 255
plt.imshow(im)

Login with LibreOne to run this code cell interactively.

If you have already signed in, please refresh the page.

cropped = im[0:50,0:50,:]
plt.imshow(cropped)
cropped = im[0:50,0:50,:]
plt.imshow(cropped)

Login with LibreOne to run this code cell interactively.

If you have already signed in, please refresh the page.

cropped = im[50:,350:610,:]
plt.imshow(cropped)
cropped = im[50:,350:610,:]
plt.imshow(cropped)

Login with LibreOne to run this code cell interactively.

If you have already signed in, please refresh the page.

red = im[:,:,0]
plt.imshow(red)
plt.colorbar()
red = im[:,:,0]
plt.imshow(red)
plt.colorbar()

Login with LibreOne to run this code cell interactively.

If you have already signed in, please refresh the page.

#Note python changed slightly since the making of the video.  
# We added the astype funciton to ensure that values are between 0-255
red_only = np.zeros(im.shape).astype(int)
red_only[:,:,0] = red

plt.imshow(red_only)
#Note python changed slightly since the making of the video.  
# We added the astype funciton to ensure that values are between 0-255
red_only = np.zeros(im.shape).astype(int)
red_only[:,:,0] = red

plt.imshow(red_only)

Login with LibreOne to run this code cell interactively.

If you have already signed in, please refresh the page.

green_only = np.zeros(im.shape).astype(int)
green_only[:,:,1] = im[:,:,1]

plt.imshow(green_only)
green_only = np.zeros(im.shape).astype(int)
green_only[:,:,1] = im[:,:,1]

plt.imshow(green_only)

Login with LibreOne to run this code cell interactively.

If you have already signed in, please refresh the page.

blue_only = np.zeros(im.shape).astype(int)
blue_only[:,:,2] = im[:,:,2]

plt.imshow(blue_only)
blue_only = np.zeros(im.shape).astype(int)
blue_only[:,:,2] = im[:,:,2]

plt.imshow(blue_only)
Hacer esto

Modifica el siguiente código para establecer todos los valores del canal azul en cero usando solo una línea simple de código de indexación.

Login with LibreOne to run this code cell interactively.

If you have already signed in, please refresh the page.

no_blue = im.copy()

#put your code here

plt.imshow(no_blue)
no_blue = im.copy()

#put your code here

plt.imshow(no_blue)
Pregunta

¿Cuál fue el comando que usas para establecer a cero todos los valores de blue inside no_blue?


This page titled 42.4: Indexación avanzada de Python is shared under a CC BY-NC 4.0 license and was authored, remixed, and/or curated by Dirk Colbry via source content that was edited to the style and standards of the LibreTexts platform.

Support Center

How can we help?