python
justtoomuchforyou
没人在乎。
展开
-
给定字符串调用类中的相应函数
StackOverflow给的方法:Calling a function of a module by using its name (a string) - Stack Overflow还有一些from operator import methodcaller,global(),local()的方法,这段代码是调用CustomStack中各种函数来对栈对象操作的class CustomStack: def __init__(self, maxSize: int): s.原创 2020-10-05 23:08:37 · 149 阅读 · 0 评论 -
整理python-opencv常用方法和报错
error: (-215) dims <= 2 && step[0] > 0 in function locateROI没有读取到文件,可能是路径、文件名、后缀错了error: (-215:Assertion failed) src.type() == CV_8UC1 in function threshold...原创 2020-04-08 15:49:15 · 975 阅读 · 0 评论 -
整理pytorch报错
Stack Overflow[1]中有这个问题的描述,自己写了一个dice loss,没法反向传播,报这个错。原因应该是因为用了torch.argmax(),好像这个函数不可导,所以没法反向传播。但是...原创 2020-03-10 22:54:43 · 8904 阅读 · 8 评论 -
AttributeError: module 'scipy.misc' has no attribute 'imread'
AttributeError: module 'scipy.misc' has no attribute 'imread'。查阅网上资料之后发现,大部分解决办法都是说没有安装PIL第三方库,库名现在为Pillow,推荐直接使用命令pip install Pillow进行安装,但是我的问题并没有因此得到解决,还是继续报错AttributeError: module 'scipy.misc' ha...转载 2019-12-14 15:29:22 · 259 阅读 · 0 评论 -
Linux服务器上装Anaconda和PyTorch
安装Anacondawget 要装的anaconda版本,anaconda2带的是Python2.7,anaconda3带的是3.7,不要选错了。然后bash 这个.sh文件进行安装。如果anaconda装好了还想装其他的Python版本,比如conda create --name python37 python=3.7,这样装Python3.7。然后执行activate python37...原创 2019-11-10 00:56:24 · 1153 阅读 · 0 评论 -
numpy中repeat和tile用法,区别于torch.repeat()
numpy中repeat和tile用法:原博:https://blog.csdn.net/henryghx/article/details/16906235torch.repeat()文档见:https://pytorch.org/docs/stable/tensors.html?highlight=repeat#torch.Tensor.repeatPyTorch中的r...原创 2019-09-24 21:08:28 · 3811 阅读 · 0 评论 -
pytorch DataLoader [Errno 22] invalid argument以及[Errno 32] Broken pipe
在跑网上的pytorch代码时,总是遇到同一个问题,在调用DataLoader时总会报错[Errno 22] invalid argument,通常还会由enumerate()带出,然后下一项是w.start(),网上找不到好的解决方法,好像是和Windows系统并发操作有关系,我的解决办法就是把其它所有打开的Python项目shut down,包括PyCharm和jupyter noteboo...原创 2019-08-28 11:55:07 · 749 阅读 · 1 评论 -
name 'mat' is not defined
遇到一个弱智问题,name 'xxx' is not defined,终于发现这两种导入库方式在引用上带来的区别:from numpy import *trust_matrix = mat(zeros((user_count+2, user_count+2)))或者写成:import numpytrust_matrix = numpy.mat(numpy.zeros((u...原创 2019-03-29 15:07:27 · 10392 阅读 · 2 评论 -
pandas数组逆序
用python的statsmodels做预测时遇到问题,用Yahoo拉到的数据用forecast()预测只能预测之前的数据,没办法只能把pandas数组逆序,再做预测。s = Series([4, 7, -5, 3], index=['1','2','3','4'])1 42 73 -54 3dtype: int64s2 = s.sort_index(ascendin...原创 2018-05-10 16:41:31 · 12518 阅读 · 0 评论 -
python3删除所有自定义变量
输入 reset, 选y。删除不可恢复。原创 2018-03-28 19:49:31 · 9098 阅读 · 4 评论 -
Python3使用pip安装git并获取Yahoo金融数据
Python3.6.4必须downgrade成3.5pip版本最低9.0.3自己的电脑必须已经安装好git关于anaconda prompt报错“Cannot find command 'git'”解决在anaconda prompt执行 conda install pandas-datareader报错,读prompt的错误,执行它提示的命令,把Python3.6.4降级成3.5,pip升级成9...原创 2018-03-28 19:36:50 · 10585 阅读 · 0 评论