- import scipy.misc
- import matplotlib.pyplot as plt
- import numpy as np
- # Load the Lena array
- lena = scipy.misc.lena()
- def get_indices(size):
- arr = np.arange(size)
- return arr % 4 == 0
- # Plot Lena
- lena1 = lena.copy()
- xindices = get_indices(lena.shape[0])
- yindices = get_indices(lena.shape[1])
- lena1[xindices, yindices] = 0
- plt.subplot(211)
- plt.imshow(lena1)
- lena2 = lena.copy()
- # Between quarter and 3 quarters of the max value
- lena2[(lena > lena.max()/4) & (lena < 3 * lena.max()/4)] = 0
- plt.subplot(212)
- plt.imshow(lena2)
- plt.show()
复制代码
本帖隐藏的内容
https://github.com/PlamenStilyianov/Python/tree/master/NumPy-Cookbook