# 统计图
mu, sigma =0,12
x = mu + sigma * np.random.randn(200000)
fig, ax = plt.subplots(figsize=(5,2.7), layout='constrained')# the histogram of the data
n, bins, patches = ax.hist(x,50, density=True, facecolor='00', alpha=0.75)
ax.set_xlabel('x')
ax.set_ylabel('p')
ax.set_title('Axes labels and text')
ax.text(-32,0.03,r'$\mu=0,\ \sigma=12$')
ax.grid(True)
# 图片from matplotlib.colors import LogNorm
X, Y = np.meshgrid(np.linspace(-3,3,128), np.linspace(-3,3,128))
Z =(1- X/2+ X**5+ Y**3)* np.exp(-X**2- Y**2)
fig, axs = plt.subplots(2,2, layout='constrained')
pc = axs[0,0].pcolormesh(X, Y, Z, vmin=-1, vmax=1, cmap='RdBu_r')
fig.colorbar(pc, ax=axs[0,0])
axs[0,0].set_title('pcolormesh()')
co = axs[0,1].contourf(X, Y, Z, levels=np.linspace(-1.25,1.25,11))
fig.colorbar(co, ax=axs[0,1])
axs[0,1].set_title('contourf()')
pc = axs[1,0].imshow(Z**2*100, cmap='plasma', norm=LogNorm(vmin=0.01, vmax=100))
fig.colorbar(pc, ax=axs[1,0], extend='both')
axs[1,0].set_title('imshow() with LogNorm()')
data1, data2, data3 = np.random.randn(3,100)
pc = axs[1,1].scatter(data1, data2, c=data3, cmap='RdBu_r')
fig.colorbar(pc, ax=axs[1,1], extend='both')
fig.colorbar(pc, ax=axs[1,1], extend='both')
axs[1,1].set_title('scatter()')
本题来自:力扣-每日一题
力扣 (LeetCode) 全球极客挚爱的技术成长平台https://leetcode.cn/
题解:
class Solution {public int rob(int[] nums) {int len nums.length;if(len 0)return 0;if(len 1)return nums[0];int first nums[0];int second …