自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(63)
  • 收藏
  • 关注

原创 how to calculate in bash scripts

how to calculate in bash scriptsuse bcyou can use bc to calculate the expression in bash scriptsfor more specific details, you can use man bc in your terminal.In the legacy way, we use bc like thisexpression="5+50*3/20 + (19*2)/7"echo "$expression"|b

2020-05-23 16:11:15 213

原创 why we need to use the zero_grad()

We usually see the "model.optim.zero_grad()" before the model training process. The main functionality of this is to zero the gradient. But do you know why should I do like this.

2020-05-18 16:46:47 158

原创 the difference between model.train() and model.eval()

if you have visited many codes in deep-learning writing by pytorch, you will notice that model.train() and model.eval()BUT THE DIFFERENCE BETWEEN THEM DO YOU KNOW?In many cases, the model.train() means that the model would be trained in the following cod

2020-05-18 16:10:55 169

原创 how to download cifar10 and split it into training file and testing file in python

how to use cifar10 in pythonthe first step:download the cifar10 using the shell scriptshow to split the cifar10 into training data, testing datahow to change the data more convientthe first step:download the cifar10 using the shell scripts#!/usr/bin/env

2020-05-18 11:01:49 195

原创 see the results in the shell but write it in a file

if you want to save your outputs in your screenbut u also want to see it in your screen.you can do like this.we touch a hello.py and writeprint("hello world“)then you type the command in your she...

2020-03-13 13:53:22 98

原创 using shift to sum the parameter

if you want to use a elegant way to sum up the bash script parameter.you have two ways to finish it .the first is to do like this;#! /bin/bashif [ $# -eq 0 ];then echo "something goes wrong:please...

2020-02-27 11:29:22 87

原创 not change the line when use "echo"

if you want not change your line when using the echo functionyou can do like this “echo -n xxxx”#! /bin/bashfor i in {A..D}do echo -n $i for j in {1..9} do ...

2020-02-26 10:56:46 79

原创 the #'s usage in linux ubuntu

the " ^exp " in regex expression means it begin with expthe “exp$” in regex expression means it ends with expif you want to know the length of an variableyou can use this commandip=1.1.1.1echo $...

2020-02-25 20:44:06 72

原创 how to know the parameters of networks in pytorch

if you want to see the parameters of the networks you can know thatthe parameters of network is a generator instance.class Net(nn.Module): def __init__(self): super(Net,self).__init__()...

2020-02-25 20:43:44 138

原创 how to control the multi_processor number

If you want to control the bash script’s multi process number.you can do like thisThe really scene is to add user or delete user in your ubuntu os or ping the net in your computer.#! /bin/bashrea...

2020-02-25 16:15:20 96

原创 some tests about torch tensor

if you want to transform your tensor to other types,you may do like thisafter all,you need to make sure the type of the tensor’s typeimport torchtensor=torch.rand(2,1)print(tensor.dtype())impor...

2020-02-24 11:33:38 88

原创 how to become a superuser on Linux Ubuntu

If you login with your common user,but after a while you want to change the shell to superuser.you can do like thissudo -sthen provide your passwordAfter successful login in,the $ prompt would cha...

2020-02-20 19:15:11 113

原创 how to know whether a directory existing in my ubuntu

if you want to test a directory whether existing in your ubuntu computer1:test -d /home2:echo $?if the answer is 0,it means that this directory exists.if other number,you can know that your comp...

2020-02-20 17:14:23 106

原创 some small tests about the python random module

I have done some small tests about the random module of python.here is the code and some analysisbucket=[0 for i in range(10)]for i in range(10000): seed=np.random.rand(1)[0] bucket[int(se...

2020-02-20 11:20:31 114

原创 how to execute snippet python in bash scripts

if you want to call a python shell in bash code,you can do like this.#! /bin/bashecho "hello world"/usr/bin/python <<-EOFprint("hello world")print("hello world")print("hello world")EOFec...

2020-02-19 11:34:56 89

原创 some thoughts about torchvision

For torchvision this package is comprised by some data such mnist cifar10 ,cifar100,and so on. if you want to see the details about torch tensor you c an do like thisDOWNLOAD_MNIST=Truetrain_data=to...

2020-02-18 13:07:05 134

原创 how to save a pytorch model and reload it from the pickle file

If you want to train a neural network in a GPU machine,but using it in a working scenario that the machine don't the GPU or TPU. So you can't train a neural network from scratch.Then here is a good ch...

2020-02-16 15:42:49 167

原创 the knowledge of pytoch

If you want to build a neural network using Pytorch.you have two methods.First,you can use the complete methods to bulid it .Let me show you the code before.import torchimport torch.nn as nnimport...

2020-02-16 14:33:27 133

原创 upgrade the pip for python

if you want to upgrade your pip version you can do like this.pip3 install pip -Uthen you can upgrade your pip to a latest version

2020-02-16 14:08:01 139

原创 the difference between size(N,) and size(N,M) in python

Some difference between the size=(1,) and size=(1,1)size(N,) means that the size is 1 dimension and the number of elements is NSize(M,N) means that the size is M*N namely the row equals M ,the col e...

2020-01-14 16:53:25 169

原创 专业版的pycharm注意事项

一直都是不通过,只好出此下策了。

2019-11-29 12:22:07 129

原创 Python中对numpy中举个函数的总结

2019-11-29 12:18:54 131

原创 django学习经验(下)

如果想在python的django中写一个弹出框首先需要在install_app中找到’django.contrib.messages’然后在views下面导入这个库,写入这样的代码from django.contrib import messagesdef toast(request):messages.success(request,"哈哈哈哈")...

2019-11-28 11:23:46 147

原创 django学习的一些经验

在一个文件夹下创建一个django项目,使用下面这个命令django-admin startproject mysite然后进入mysite文件夹下,启动server,python manage.py runserver在manage.py 的同一个目录下面,我们创建一个新的polls文件夹python manage.py startapp polls...

2019-11-28 11:20:16 126

原创 将函数做为形参传递给函数,以备调用

学习完组成原理和操作系统后,这一点再来看,就简单了很多,函数名就是一个地址,然后将函数的地址传递给另一个函数,就可以在这个函数里面找到了这个地址,然后就可以知道,对其进行调用,然后可以进行一些运算,其实在c++中类似于回调函数,这些其实都是这些的具体应用而已。下面是具体的实例。int fun1(){ cout<<"hello world"<<endl; retur...

2019-08-31 10:33:31 1071

原创 LeetCode中的bug

这个题其实是一个简单题,但是我在写的过中碰到了一个很有意思的现象,我不知道是不是我的代码有问题,还是LeetCode的网站有问题,我在自己电脑上的vscode、devc++,还有同学电脑上的vsstudio上运行都没有问题,但是在网站的评测系统上就是显示stack-buffer-overflow,后来我实在是被逼急了,就多加了一行代码,然后通过了。但是这样其实间接说明了网站是有问题的,我把代码贴在...

2019-08-11 16:06:05 320

原创 记一个内核代码中的用法

在linux内核中,有很多有意思的代码,下面我来记录一下,#include<iostream>#include<bits/stdc++.h>#define DUMP_WRITE(sum,i) {sum+=10;i++;} //这个宏定义不需要定义变量的类型 //上面这个宏定义是不正确的,因为有两条语句,如果玉遇到下面的情况,就会报错,else without ...

2019-08-11 15:56:48 90

原创 归并排序不是递归版的

归并排序有两种写法,有一种是基于递归的,有一种是基于迭代的,基于迭代的是一种有倍增的思想在里面,#include<iostream>#include<vector>using namespace std;void merge_sort1(vector<int>& vec,int low,int high){ ...

2019-08-10 17:00:57 120

原创 快速排序

快速排序是一个很重要的算法,这里记录一个很鲁棒的写法,为什么引入变量temp,因为后面需要将其归位,为什么从high开始进行更新,因为第一个值被temp记录下来,就是一个废值,所以知道直接将不满足条件的high给覆盖到low上面去,就是因为他是一个废掉的值。下面直接在代码中写出自己的理解,#include<iostream>#include<vector>usin...

2019-08-10 15:51:36 149

原创 如何判断一个方阵是不是一个合格的方阵

一个典型的以空间换取时间的编程案例

2019-07-01 22:11:17 473

原创 智能剪刀算法+详细注释

//#include&lt;opencv2/core/core.hpp&gt;//#include&lt;iostream&gt;//#include&lt;opencv2/highgui/highgui.hpp&gt;//#include&lt;opencv2/imgproc.hpp&gt; //#include&lt;vector&gt;//#include&lt;m...

2018-11-12 16:56:32 2296 23

原创 使用sklearn上的数字测试kNN算法

import numpy as npfrom sklearn import datasetsdigits=datasets.load_digits()x=digits.datay=digits.targetfrom sklearn.model_selection import train_test_splitX_train,X_test,y_train,y_test=train_te...

2018-10-24 21:28:20 315

原创 python实现knn算法

import numpy as npfrom math import sqrtfrom collections import Counterx=np.random.randint(1,5,size=(4,5))xx=np.reshape(x,(-1,2))y=np.random.randint(0,2,10)#创建一个一维数组,并且指定范围为0,1,大小为10print(y.sha...

2018-10-24 18:41:36 427

原创 一个检验梯度下降的工具包

import numpy as npdef dg_bug(theta,X_b,y, episilon=0.001): res=np.empty(len(theta)) for i in range(len(theta)): theta_1=theta.copy() theta_1[i]+=episilon theta_2=theta.copy() theta_2[i]-=e...

2018-10-22 20:34:26 153

原创 用python实现一个简单的梯度下降程序

import mathimport matplotlib.pyplot as pltimport numpydef dj(theta): return 2*(theta-2.5)#这里返回theta对应的导数,而函数求导是手动进行的def j(theta): return (x-2.5)**2-1def __name__=="__main__":#定义程序的入口 x=np.lin...

2018-10-21 19:57:29 1388 1

原创 python线性回归相关实现

import numpy as npimport matplotlib.pyplot as pltx=np.array([1.,2.,3.,4.,5.])y=np.array([1.,3.,2.,3.,5.])plt.scatter(x,y)这里画出的是散点图plt.axis([0,6,0,6])设置坐标的大概范围plt.show()画出图像x_mean=np.mean(x)用np包...

2018-10-21 10:10:01 221

原创 第一篇博客

    今天是第一次开通博客,以前也知道这个,但是从来都是搜索别人的源代码,自己可能没有啥水平写出优秀的文档来。但是即来之,则安之,我还是不定期的更新几篇的,虽然都是水贴,可能根本不会对其他人产生积极的影响,然而,我就认为是写给我自己看的,不说了还是抓紧时间去a题吧,没有想到这个帖子竟然没有发出去过,啊啊啊啊...

2018-10-21 10:05:56 87

原创 nyoj33蛇形填数

   这道题当时第一眼见到的时候,感觉真的是一脸懵逼,真的不知道是怎么一回事,最后想了一下,不就是回环的进行填数吗,于是我就尝试用了很多while循环,于是就改了好久,终于AC了,这道题当然现在看,可能没有那么难,可是却实伤了脑细胞啊!!不说了,贴代码。蛇形填数时间限制:3000 ms  |  内存限制:65535 KB难度:3描述在n*n方陈里填入1,2,...,n*n,要求...

2018-10-21 10:03:28 77

原创 几个二分查找的变形

二分查找其实是很难的问题,主要是边界问题难以解决,下面就我自己的理解说一说,我们应该如何进行思考。二分法主要面向两类问题,一类是无重复元素的按升序排序的数组另一类是面向有重复元素的数组。而每一类都必须面临两个难点,对应如下 1:如何将问题的规模减小,因为二分就是分治的应用,我们必须要保证问题在逐步减小,不会出现死循环的情况。2:while循环终止的条件,是选用low&l...

2018-10-21 10:02:32 190

原创 c++点滴

查看某个变量的基本信息,要用到的函数是typeid(待查的数据).name(),使用之前要包含头文件#include&lt;typeinfo&gt;,不然会报错,查询出来的结果中d代表的是double...

2018-10-21 10:02:06 102

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除