![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
hellopari
这个作者很懒,什么都没留下…
展开
-
tensorflow2.0如何导入本地mnist数据
#将本地的minst数据放入以下路径:: 当前目录 -> mnist.npzfrom tensorflow.keras.datasets import mnist(X_train, Y_train), (X_test, Y_test) = mnist.load_data(path=current_dir+'/mnist.npz')原创 2021-05-12 19:30:08 · 1290 阅读 · 0 评论 -
调参代码
test_value=[np.arange(0.001,0.01,0.001),np.arange(0.01, 0.1, 0.01),np.arange(0.1, 1, 0.1),np.arange(1, 10,1),np.arange(10, 100, 10),np.arange(100, 1000, 100)] for j in np.arange(0, len(test_value), 1): for k in test_value[j]: ...原创 2021-05-09 09:41:24 · 250 阅读 · 0 评论 -
python报错:RuntimeError: CUDA error: invalid device ordinal
只需要在用到device的地方,如torch.Tensor([(self._dim + 1) / 2], device=self.device)加上这句话即可,表示又cuda就用cuda,没有的话就用cpudevice = torch.device(“cuda:0” if torch.cuda.is_available() else “cpu”)ps:可以把"cuda:0"换成"cuda:1"试试...原创 2021-03-19 21:14:12 · 1673 阅读 · 0 评论 -
pytorch报错:RuntimeError: CUDA error: device-side assert triggered
模型输出的维度需要与类别数相等,比如classifier = Classifier(INPUT_DIM, HIDDEN_DIM, OUTPUT_DIM).to(DEVICE)logit = classifier(data)data如果有5个类,那么OUTPUT_DIM也应该设置为5原创 2021-02-21 15:57:58 · 424 阅读 · 0 评论 -
python找到多维list中某列最大的值所在行数据
list=[] for i in np.arange(0,10): list.append(np.array([10*i,i])) list=np.array(list) max=np.max(list[:,0]) max_index=np.where(list[:,0]==int(max))[0] print(max,np.array(list)[max_index,:])原创 2021-02-18 15:41:38 · 2292 阅读 · 1 评论 -
python如何读取文件夹下所有文件及其子文件
def file_name(file_dir): for root, dirs, files in os.walk(file_dir): print(root) #当前目录路径 print(dirs) #当前路径下所有子目录 print(files) #当前路径下所有非目录子文件原创 2021-01-16 21:00:12 · 1928 阅读 · 1 评论 -
linux下载tensorflow-gpu对用版本cuda,cuDNN
https://tensorflow.google.cn/install/source_windows原创 2021-01-15 10:52:17 · 452 阅读 · 0 评论 -
疑问:为什么在命令行输入conda install keras=2.3.1和pip install keras==2.3.1的结果完全不同
1:在当前虚拟环境下,输入conda install keras=2.3.1命令的时候,需要下载这么多安装包2:在同样的情况下输入pip install keras==2.3.1请问大佬们,这是什么原因呢原创 2020-11-29 22:02:31 · 2655 阅读 · 0 评论 -
python常用小知识点
1:返回x中各值出现的次数在这里插入代码片a=np.bincount(x)2:读取excel文件中的数据name_head = 'char'train_names = ['01(B)', '02(D)']pd.read_excel('{}/S{}/S{}_train_data.xlsx'.format(DATASETS_DIR, i, i), sheet_name=name_head + train_names[j], header=None).values3:返回数据中指定值的下标 np原创 2020-11-28 16:50:10 · 189 阅读 · 0 评论 -
python pip install报错 from pip._internal.utils.entrypoints import _wrapper ImportError: cannot import
好像是因为pyhton不可用,可以尝试使用conda install原创 2020-11-26 14:29:23 · 954 阅读 · 0 评论 -
python之增加变换轴的维度
1:增加维度x[np.newaxis, :, :]将x从两维增加成三维,np.newaxis放在第一个表示在第一维增加2:变换轴的维度x.transpose(2, 0, 1)表示将三个维度的顺序调换原创 2020-11-23 21:01:02 · 241 阅读 · 0 评论 -
记录无法解决无法启动jupyter的过程
前提:使用anaconda直接安装jupyter notebook。打开Anaconda Prompt在命令行输入jupyter notebook报错’jupyter’ 不是内部或外部命令,也不是可运行的程序把anaconda目录下的两个路径添加进环境变量里面C:\Users\pari\Anaconda3\ScriptsC:\Users\pari\Anaconda3\Scripts2:报错: No module named ‘importlib_metadata’conda install -原创 2020-11-22 17:06:00 · 468 阅读 · 0 评论 -
对数据用TruncatedSVD,TSEN降维后根据真实标签可视化
def plot_clustering(z_run, labels, engine ='plotly', download = False, folder_name ='clustering'): """ Given latent variables for all timeseries, and output of k-means, run PCA and tSNE on latent vectors and color the points using cluster_labels.原创 2020-11-20 16:02:25 · 574 阅读 · 0 评论 -
聚类指标SI,CH,ACC,NMI,AR,AMI的python函数实现
def console_log(pred, data=None, labels=None, model_name='cluster', newJ=None, verbose=1): measure_dict = dict() if data is not None: measure_dict['si'] = SI(data, pred) measure_dict['ch'] = CH(data, pred) if labels is not None原创 2020-11-20 10:45:48 · 3059 阅读 · 5 评论 -
报错TypeError: only length-1 arrays can be converted to Python scalars
int(x)报错:TypeError: only length-1 arrays can be converted to Python scalars试试:x.astype(int)或者np.vectorize(x)原创 2020-11-17 10:10:07 · 11924 阅读 · 0 评论 -
python项目创建新的虚拟环境并指定python版本
(PS:以下操作前提:安装了anaconda)1:在运行的输入找到:anaconda prompt2:cd 到anaconda 安装目录下的envs目录下如:cd C:\Users\pari\Anaconda3\envs3:输入conda create -n *** python=3.6其中***为创建的空间的名字,可以指定python的版本也可以不指定4:创建过程中询问是否安装以下依赖,输入y,表示是创建成功后,该空间会出现在Anaconda3\envs目录下5在项目中使用此环原创 2020-11-15 20:29:20 · 1061 阅读 · 0 评论 -
python之继承知识点
https://blog.csdn.net/weixin_44239343/article/details/86522556子类继承父类属性的问题https://blog.csdn.net/qq_36786467/article/details/108417560原创 2020-11-13 17:27:20 · 61 阅读 · 0 评论 -
明明下载了包却无法引入其下模块的问题
pip 下载了 **from .* import ^^报错:No module named ‘.*’可能原因,安装的此包的版本不对,新的版本改模块可能已经删除,因此应该根据github上的提示下载指定的版本原创 2020-11-13 16:06:26 · 444 阅读 · 0 评论 -
卷积神经网络的计算过程
https://www.cnblogs.com/shine-lee/p/9932226.html转载 2020-11-08 19:35:02 · 147 阅读 · 0 评论 -
python报错‘dict_keys‘ object has no attribute ‘sort‘
python2中,字典有sort这个属性python3中,字典没有sort这个属性解决办法,使用sorted(arg)原创 2020-09-03 20:21:01 · 5701 阅读 · 0 评论 -
从github下载的python的机器学习代码后容易遇到的问题
下载后的代码,可能会出现很多问题,如:1:ModuleNotFoundError: No module named ‘xxx’当遇到这个问题的时候,去pip install 也没有用,报错Could not find a version that satisfies the requirement ,说明这个包在这个文件里,网上下载不了2:python同级目录下引用失败3:报错 No module named ‘ConfigParser’在 Python 3.x 版本后,ConfigParser.原创 2020-09-03 16:23:28 · 1433 阅读 · 1 评论 -
python绘制3d球体网格散点图
前提:如果你的数据是三维的,然后你想把他们分布到一个网格的球体上如果有类别标签,可以分颜色描绘from mpl_toolkits.mplot3d import Axes3Dimport matplotlib.pyplot as pltimport numpy as npfrom itertools import product, combinationsfig = plt.figure()ax = fig.gca(projection='3d')# draw sphereu, v原创 2020-09-02 13:53:14 · 4156 阅读 · 4 评论 -
cannot import name 'xx' from 'xxxx'
报错ImportError: cannot import name ‘Module’ from ‘torch.nn.modules.module’找了半天,百度也没找到结果最后发现是自己手抖不小心改了module.py里面的名字,结果所有神经网络代码都报这个错,希望对由此问题感到迷茫的人有所帮助...原创 2019-11-07 16:47:52 · 4634 阅读 · 2 评论 -
pip安装pytest,报错Defaulting to user installation because normal site-packages is not writeable
不要一直安装pytestpytest只是一种测试模式,把它关闭即可关闭教程https://blog.csdn.net/cvnlixiao/article/details/87351491转载 2020-10-08 10:18:37 · 17805 阅读 · 0 评论 -
python如何拿到当前文件路径并向后拼接新的目录
ROOT_DIR = os.path.dirname(os.path.abspath(file))原创 2020-11-08 16:05:49 · 1280 阅读 · 0 评论