![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python学习
智商太低会传染
这个作者很懒,什么都没留下…
展开
-
使用 plt.savefig() 保存图片去除旁边的空白区域
plt.gca().xaxis.set_major_locator(plt.NullLocator())plt.gca().yaxis.set_major_locator(plt.NullLocator())#plt.show()plt.savefig(name,bbox_inches = 'tight',pad_inches = 0)经过实验,这个确实可以去掉白边原创 2021-03-29 16:56:43 · 667 阅读 · 0 评论 -
python中zip(*)作用
类似于zip打包命令一样,与之相反的命令是操作当有多个迭代器,希望它们能一起输出时(相同索引),会使用zip()命令,在训练模型的时候最常用于collect_fun函数中,该函数将多个dataset传的东西打成一个zip包,之后将该zip报分解开images, labels = zip(*batch)这样利用zip(*)命令将batch解压开原文链接...转载 2021-01-25 10:28:37 · 1076 阅读 · 0 评论 -
python中的np.array中的作用
import numpy as npx=[[1,2,3],[4,5,6],[7,8,9]]y=np.array(x)print(x)print(y)输出结果:[[1, 2, 3], [4, 5, 6], [7, 8, 9]][[1 2 3] [4 5 6] [7 8 9]]总结:np.array()可以把列表中数据转换为矩阵或者张量。原创 2021-01-24 23:44:44 · 3953 阅读 · 0 评论 -
python中[-1]、[:-1]等几种切片的作用
import numpy as npa=np.random.rand(5)print(a)[ 0.64061262 0.8451399 0.965673 0.89256687 0.48518743] print(a[-1]) ###取最后一个元素[0.48518743] print(a[:-1]) ### 除了最后一个取全部[ 0.64061262 0.8451399 0.965673 0.89256687] print(a[::-1]) ### 取从后向前原创 2021-01-24 18:46:40 · 551 阅读 · 0 评论 -
Python.__getitem__方法
转载Python的魔法方法__getitem__ 可以让对象实现迭代功能,这样就可以使用for…in… 来迭代该对象了class Animal: def __init__(self, animal_list): self.animals_name = animal_listanimals = Animal(["dog","cat","fish"])for animal in animals: print(animal)在用 for…in… 迭代对象时,如果对象没转载 2021-01-24 12:38:00 · 109 阅读 · 0 评论 -
read(),readline(),readlines()方法学习
在python中读取文件常用的三种方法:read(),readline(),readlines()。假设a.txt,里面保存了hello welcome一、read([size])方法read([size])方法从文件当前位置起读取size个字节,若无参数size,则表示读取至文件结束为止,它范围为字符串对象f = open("a.txt")lines = f.read()print (lines)print(type(lines))f.close()输出结果:HelloWelco转载 2021-01-24 11:05:54 · 7822 阅读 · 1 评论 -
argparse模块用法
##理解 argparse 模块 :argsparse是python的命令行解析的标准模块,内置于python,不需要安装。这个库可以让我们直接在命令行中就可以向程序中传入参数并让程序运行。传入一个参数我们先在桌面新建“arg学习”的文件夹,在该文件夹中新建demo.py文件,来看一个最简单的argsparse库的使用的例子。import argparseparser = argparse.ArgumentParser(description=‘命令行中传入一个数字’)#type是要传入的参数的转载 2021-01-21 19:34:55 · 191 阅读 · 0 评论