Sayarara's notebook

blogs/notes/readings


  • Home

  • Archives

  • Search

NumPy

Posted on 2018-12-03 | In notes.tools

NumPy教程
http://www.runoob.com/numpy/numpy-tutorial.html

PyTorch的基础。

pipenv安装与使用

Posted on 2018-11-30 | In notes.tools

pipenv使用 Pipfile 和 Pipfile.lock 来管理和维护项目的依赖包,实现虚拟环境运行,避免了包冲突问题

安装与使用

安装
pip3 install pipenv
创建空目录
mkdir myproject
cd myproject
pipenv install requests

如果运行成功,则生成一个 Pipfile。

安装完Requests,创建一个简单的 main.py

1
2
3
4
import requests

response = requests.get('https://httpbin.org/ip')
print('Your IP is {0}'.format(response.json()['origin']))

测试运行
pipenv run python main.py

1
2
3
4
5
6
7
8
9
10
11
pipenv shell 激活虚拟环境   exit退出虚拟环境
pipenv graph 查看目前安装的库及其依赖
pipenv install django==1.11 安装固定版本模块并加入到Pipfile
pipenv install django 安装最新?默认版本模块并加入到Pipfile
pipenv install pytest --dev 通过添加 –dev 参数 来区分开发环境
pipenv uninstall django 卸载第三方库
pipenv uninstall --all 卸载全部包并从Pipfile中移除
pipenv --venv 获得虚拟环境路
pipenv --py 获取虚拟环境 Python 解释器路径
pipenv --site-packages 加载系统 Python包 (默认新创建的虚拟环境不包含第三方包)
pipenv lock 产生Pipfile.lock文件(默认会自己产生)

官方文档:https://pipenv.readthedocs.io/en/latest/#pipenv-usage

InstallError

TLS/SSL缺失

问题描述
[pipenv.exceptions.InstallError]: [‘pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
python2版本,import ssl无错误
pyton3.6.1, import ssl 显示no moudle named _ssl

解决方法
python pip 出现locations that require TLS/SSL异常处理方法: https://blog.csdn.net/zhengcaihua0/article/details/79681991

1
2
3
4
5
6
7
8
9
10
查看openssl安装包,看是否缺少openssl-devel包 
# rpm -aq|grep openssl
yum安装openssl-devel
# yum install openssl-devel -y

对python3.6进行编译安装
cd Python-3.6.1
./configure --with-ssl
make
sudo make install

允许安装的python3使用ssl功能模块,进入python3中,执行import ssl无错误

Locking Failed

问题描述:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Creating a Pipfile for this project…
Installing requests…
✔ Installation Succeeded
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
✘ Locking Failed!
[pipenv.exceptions.ResolutionFailure]: File "/usr/local/lib/python3.6/site-packages/pipenv/resolver.py", line 69, in resolve
[pipenv.exceptions.ResolutionFailure]: req_dir=requirements_dir
[pipenv.exceptions.ResolutionFailure]: File "/usr/local/lib/python3.6/site-packages/pipenv/utils.py", line 695, in resolve_deps
[pipenv.exceptions.ResolutionFailure]: req_dir=req_dir,
[pipenv.exceptions.ResolutionFailure]: File "/usr/local/lib/python3.6/site-packages/pipenv/utils.py", line 469, in actually_resolve_deps
[pipenv.exceptions.ResolutionFailure]: resolved_tree = resolver.resolve()
[pipenv.exceptions.ResolutionFailure]: File "/usr/local/lib/python3.6/site-packages/pipenv/utils.py", line 408, in resolve
[pipenv.exceptions.ResolutionFailure]: raise ResolutionFailure(message=str(e))
[pipenv.exceptions.ResolutionFailure]: pipenv.exceptions.ResolutionFailure: ERROR: ERROR: Could not find a version that matches requests
[pipenv.exceptions.ResolutionFailure]: No versions found
[pipenv.exceptions.ResolutionFailure]: Warning: Your dependencies could not be resolved. You likely have a mismatch in your sub-dependencies.
First try clearing your dependency cache with $ pipenv lock --clear, then try the original command again.
Alternatively, you can use $ pipenv install --skip-lock to bypass this mechanism, then run $ pipenv graph to inspect the situation.
Hint: try $ pipenv lock --pre if it is a pre-release dependency.
ERROR: ERROR: Could not find a version that matches requests
No versions found
Was https://pypi.org/simple reachable?
[pipenv.exceptions.ResolutionFailure]: req_dir=requirements_dir
[pipenv.exceptions.ResolutionFailure]: File "/usr/local/lib/python3.6/site-packages/pipenv/utils.py", line 695, in resolve_deps
[pipenv.exceptions.ResolutionFailure]: req_dir=req_dir,
[pipenv.exceptions.ResolutionFailure]: File "/usr/local/lib/python3.6/site-packages/pipenv/utils.py", line 469, in actually_resolve_deps
[pipenv.exceptions.ResolutionFailure]: resolved_tree = resolver.resolve()
[pipenv.exceptions.ResolutionFailure]: File "/usr/local/lib/python3.6/site-packages/pipenv/utils.py", line 408, in resolve
[pipenv.exceptions.ResolutionFailure]: raise ResolutionFailure(message=str(e))
[pipenv.exceptions.ResolutionFailure]: pipenv.exceptions.ResolutionFailure: ERROR: ERROR: Could not find a version that matches requests
[pipenv.exceptions.ResolutionFailure]: No versions found
[pipenv.exceptions.ResolutionFailure]: Warning: Your dependencies could not be resolved. You likely have a mismatch in your sub-dependencies.
First try clearing your dependency cache with $ pipenv lock --clear, then try the original command again.
Alternatively, you can use $ pipenv install --skip-lock to bypass this mechanism, then run $ pipenv graph to inspect the situation.
Hint: try $ pipenv lock --pre if it is a pre-release dependency.
ERROR: ERROR: Could not find a version that matches requests
No versions found
Was https://pypi.org/simple reachable?

  1. 检查https://pypi.org/simple是否能打开。
    1
    2
    pipenv.patched.notpip._vendor.urllib3.exceptions.ReadTimeoutError: 
    HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.

更换国内源

  • 阿里云:http://mirrors.aliyun.com/pypi/simple/
  • 豆瓣:http://pypi.douban.com/simple/
  • 清华大学:https://pypi.tuna.tsinghua.edu.cn/simple/
  • 中国科学技术大学:https://pypi.mirrors.ustc.edu.cn/simple/

修改 Pipfile 文件默认源

1
2
3
4
5
查看 Pipfile 的内容: 
cat Pipfile
编辑Pipfile:
vim Pifile
将url = "https://pypi.org/simple"改为url = "https://pypi.tuna.tsinghua.edu.cn/simple/"

  1. 跳过lock
    pipenv install —skip-lock
    失效,出现TLS/SSL缺失,解决后TLS/SSL缺失问题后,该问题解决。

pipenv命令

在pipenv虚拟环境目录下,输入 pipenv 命令可查看命令的完整用法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
Usage: pipenv [OPTIONS] COMMAND [ARGS]...

Options:
--update Update Pipenv & pip to latest.
--where Output project home information.
--venv Output virtualenv information.
--py Output Python interpreter information.
--envs Output Environment Variable options.
--rm Remove the virtualenv.
--bare Minimal output.
--completion Output completion (to be eval'd).
--man Display manpage.
--three / --two Use Python 3/2 when creating virtualenv.
--python TEXT Specify which version of Python virtualenv should use.
--site-packages Enable site-packages for the virtualenv.
--jumbotron An easter egg, effectively.
--version Show the version and exit.
-h, --help Show this message and exit.


Usage Examples:
Create a new project using Python 3.6, specifically:
$ pipenv --python 3.6

Install all dependencies for a project (including dev):
$ pipenv install --dev

Create a lockfile containing pre-releases:
$ pipenv lock --pre

Show a graph of your installed dependencies:
$ pipenv graph

Check your installed dependencies for security vulnerabilities:
$ pipenv check

Install a local setup.py into your virtual environment/Pipfile:
$ pipenv install -e .

Commands:
check Checks for security vulnerabilities and against PEP 508 markers
provided in Pipfile.
graph Displays currently–installed dependency graph information.
install Installs provided packages and adds them to Pipfile, or (if none
is given), installs all packages.
lock Generates Pipfile.lock.
open View a given module in your editor.
run Spawns a command installed into the virtualenv.
shell Spawns a shell within the virtualenv.
uninstall Un-installs a provided package and removes it from Pipfile.
update Uninstalls all packages, and re-installs package(s) in [packages]
to latest compatible versions.


Commands:
check 检查安全漏洞
graph 显示当前依赖关系图信息
install 安装虚拟环境或者第三方库
lock 锁定并生成Pipfile.lock文件
open 在编辑器中查看一个库
run 在虚拟环境中运行命令
shell 进入虚拟环境
uninstall 卸载一个库
update 卸载当前所有的包,并安装它们的最新版本

vim指令清单

Posted on 2018-11-27 | In notes.tools

指令大全:https://blog.csdn.net/feosun/article/details/73196299

启动vim

  • vim 直接启动vim
  • vim filename 打开vim并创建名为filename的文件

打开文件

  • vim file 打开单个文件
  • vim file1 file2 file3 … 同时打开多个文件

退出

按ESC键 跳到命令模式,然后输入:q(不保存)或者:wq(保存) 退出。

  • :w 保存文件但不退出vi
  • :w file 将修改另外保存到file中,不退出vi
  • :w! 强制保存,不推出vi
  • :wq 保存文件并退出vi
  • :wq! 强制保存文件,并退出vi
  • :q 不保存文件,退出vi
  • :q! 不保存文件,强制退出vi
  • :e! 放弃所有修改,从上次保存文件开始再编辑命令历史

模式

  • 正常模式(按Esc或Ctrl+[进入) 左下角显示文件名或为空
  • INSERT, 插入模式(按i键进入?) 左下角显示–INSERT–
  • VISUAL BLOCK, (按v键进入?) 左下角显示–VISUAL–

linux常用命令清单

Posted on 2018-11-26 | In notes.tools

文件夹与文件操作

创建文件夹
mkdir testpipenv

进入文件夹
cd testpipenv

返回当前目录上一层
cd ..

查看当前所处目录位置
pwd

压缩与解压缩

解压

  • 对于.tar结尾的文件
    tar -xf all.tar
  • 对于.gz结尾的文件
    gzip -d all.gz
    gunzip all.gz
  • 对于.tgz或.tar.gz结尾的文件
    tar -xzf all.tar.gz
    tar -xzf all.tgz
  • 对于.bz2结尾的文件
    bzip2 -d all.bz2
    bunzip2 all.bz2
  • 对于tar.bz2结尾的文件
    tar -xjf all.tar.bz2
  • 对于.Z结尾的文件
    uncompress all.Z
  • 对于.tar.Z结尾的文件
    tar -xZf all.tar.z

OmniGraffle使用小技巧

Posted on 2018-11-14 | In notes.tools

插入latex公式

  • option+空格 找到LaTeXiT
  • 在输入框中输入latex公式,选择text,点击latex it!
  • 将生成的图形拖动到OmniGraffle的版面

CentOS系统 服务器环境配置

Posted on 2018-11-12 | In notes.tools

远程连接

Mac系统,终端terminal
ssh 服务器用户名@ip (如:ssh root@xxx.xxx.xxx.xxx)
输入密码

python3安装

开发依赖:

# yum -y groupinstall development
# yum -y install zlib-devel

安装python:

[root@VM_58_11_centos ~]# wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz  获取安装包

[root@VM_58_11_centos ~]# tar -zxf Python-3.6.1.tgz  解压缩

[root@VM_58_11_centos ~]# cd Python-3.6.1   定位到文件夹

#查看安装包文件
[root@VM_58_11_centos Python-3.6.1]# ls
[root@localhost Python-3.6.1]# ./configure  添加配置
[root@localhost Python-3.6.1]# make      编译源码
[root@localhost Python-3.6.1]# make install     执行安装

xampp

xampp安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# wget http://sourceforge.net/projects/xampp/files/XAMPP%20Linux/5.6.14/xampp-linux-x64-5.6.14-0-installer.run  xampp下载
# chmod 777 xampp-linux-x64-5.6.14-0-installer.run 赋执行权限
# ./xampp-linux-x64-5.6.14-0-installer.run    安装
# /opt/lampp/lampp start 启动xampp
# /opt/lampp/lampp stop 停止xampp
# /opt/lampp/lampp security 设置密码

卸载xampp
# /opt/lampp/lampp stop
# rm -rf /opt/lampp

添加开机启动服务
sudo ln -s /opt/lampp/lampp /etc/init.d/lampp
sudo chkconfig --add lampp

远程连接mysql报错

2013 - Lost connection to MySQL server at ‘reading initial communication packet’, system error: 0

未解决

MySQL

安装

[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm 
[root@localhost src]# rpm -ivh mysql57-community-release-el7-8.noarch.rpm 
[root@localhost src]#  yum -y install mysql-server 

配置my.cnf

vim /etc/my.cnf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
server_id = 1
expire_logs_days = 3

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

启动mysql服务

service mysqld restart

重置密码

获取随机产生的密码
# grep "password" /var/log/mysqld.log    
1
2
[root@VM_32_16_centos ~]# grep "password" /var/log/mysqld.log
2018-11-28T07:30:50.436132Z 1 [Note] A temporary password is generated for root@localhost: La2aQvn&M=o-
使用该密码进入数据库

[root@VM_32_16_centos ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.24

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
重置密码前无法操作数据库
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
修改密码

密码需为包含大小写,数字及符号的字符串
alter user ‘root’@’localhost’ identified by ‘包含大小写,数字及符号的字符串’;

添加新用户
grant all on *.* to 'newroot'@'%' identified by '密码'  with grant option;

@’%’可以任意IP登录,@IP地址则限制只能让指定IP登录

刷新权限
 flush privileges;

远程连接

2003 - Can't connect to MySQL server on 'XXX.xxx.xxx.xxx'

参考Remote Access MySQL connection error:https://stackoverflow.com/questions/29370829/remote-access-mysql-connection-error?spm=a2c4e.11153940.blogcont614613.12.57664a72R9A5pg

检查tcp

[root@VM_32_16_centos ~]# nc -l -p 3306
Ncat: bind to :::3306: Address already in use. QUITTING.

如果没有安装nc,先安装

# yum install nc

检查端口

[root@VM_32_16_centos ~]# nc ip地址 3306
Ncat: Connection timed out.

If this is not working, this is not a mysql server configuration issue but a network issue, and you must check your router firewall rules.
Otherwise, your problem comes from mysql server settings. Check your mysql configuration file for bind-address, and remove them to make mysqld accept clients from any IP address.

防火墙问题。

解决方法(已解决)

通过使用SSH通过连接。端口22,用户名密码为使用ssh登陆服务器时的用户名密码,常规里ip为localhost,端口3306,用户名密码为mysql的用户名密码。

Windows系统重装系统环境配置清单

Posted on 2018-11-12 | In notes.tools

数据库

mysql,安装XAMPP,mysql文件夹中的data文件夹直接替换

navicat for mysql,免安装版

  • 百度网盘链接:https://pan.baidu.com/s/1GMXLmG5K2uBwT8a-bP_E7A
  • 提取码:xkm5
  • 注册码 NAVH-WK6A-DMVK-DKW3

编辑器

Atom

跨平台文本编辑器

Pycharm

凭.edu邮箱获取1年使用期限的注册码

压缩刻录

Bandizip

远程连接服务器

MobaXterm

全功能终端软件

  • 链接:https://pan.baidu.com/s/1jxu1Cr6uXMay3kRqJxqqrQ
  • 提取码:fb1g

putty

代码版本控制

SourceTree

拥有可视化界面的Git客户端

免登录,跳过初始注册的方法:

  • 首先,安装完 SourceTree 以后先运行一次,弹出初始化登录页面后退出。
  • 在C:\Users\你的电脑名字\AppData\Local\Atlassian\SourceTree目录下新建一个全名为 accounts.json 的文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[
{
"$id": "1",
"$type": "SourceTree.Api.Host.Identity.Model.IdentityAccount, SourceTree.Api.Host.Identity",
"Authenticate": true,
"HostInstance": {
"$id": "2",
"$type": "SourceTree.Host.Atlassianaccount.AtlassianAccountInstance, SourceTree.Host.AtlassianAccount",
"Host": {
"$id": "3",
"$type": "SourceTree.Host.Atlassianaccount.AtlassianAccountHost, SourceTree.Host.AtlassianAccount",
"Id": "atlassian account"
},
"BaseUrl": "https://id.atlassian.com/"
},
"Credentials": {
"$id": "4",
"$type": "SourceTree.Model.BasicAuthCredentials, SourceTree.Api.Account",
"Username": "",
"Email": null
},
"IsDefault": false
}
]
  • 重启SourceTree

SourceTree通过配置SSH来链接Github

https://blog.csdn.net/tengdazhang770960436/article/details/54171911

  • 使用 git bash的生成公私钥:id_rsa、id_rsa.pub

    $ git config —global user.name “sayarara”

    $ git config —global user.email “xxx.mail@xxx.com”

  • 生成 SSH 密钥
    $ ssh-keygen -t rsa -C “xxx.mail@xxx.com”
    按3个回车,密码为空。

  • 设置 SourceTree 的 SSH客户端,工具->选项 ,选择.ssh 目录下的 id_rsa

  • 添加 ~/.ssh/id_rsa.pub 文件内容到 git 服务器

安装python库失败

Microsoft visual c++ 14.0 is required错误

安装包地址:

  • 链接:https://pan.baidu.com/s/1Jon9u5V8z7ushkLxIj9Igg
  • 提取码:1i95
成功
  • sklearn
  • datasketch
  • nltk
  • matplotlib

x86_amd64\\cl.exe’ failed with exit status 2

安装dedupe出现该错误。
未解决。

django与MySQL

Posted on 2018-09-03 | In bug

django2.1新手教程

http://www.liujiangblog.com/blog/36/

数据库同步操作

https://www.jianshu.com/p/22aa7cca7ff6

自动生成sql语句

django会根据setting.py中指定的数据库自动生成sql语句:

    python manage.py makemigrations

查看自动生成的sql语句

python manage.py sqlmigrate 【appname】 【no】
例:python manage.py sqlmigrate myblog 0001

自动同步到数据库

python manage.py migrate

bug: MySQL Strict Mode

WARNINGS:
    ?: (mysql.W002) MySQL Strict Mode is not set for database connection 'default'
    HINT: MySQL's Strict Mode fixes many data integrity problems in MySQL, such as data truncation upon insertion, by escalating warnings into errors. It is strongly recommended y
    ou activate it. See: https://docs.djangoproject.com/en/2.1/ref/databases/#mysql-sql-mode
解决方法1

在settings中,在DATABASES变量定义处下面添加

    DATABASES['OPTIONS']['init_command'] = "SET sql_mode='STRICT_TRANS_TABLES'"
解决方法2
1
2
3
4
5
6
7
8
9
10
11
12
13
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'cluster',
'USER':'root',
'PASSWORD':'',
'HOST':'localhost',
'PORT':'3306',
'OPTIONS':{
'init_command':"SET sql_mode='STRICT_TRANS_TABLES'",
}
}
}

bug: 无法自动生成表

Running migrations: No migrations to apply.

solution
  • 第一步: 删除该app名字下的migrations文件(migration文件夹中的000x-initial.py文件,存储了自动生成的sql创表语句)。
  • 第二步: 进入数据库,找到django_migrations的表,删除表中app字段为该app名字的所有记录。
  • 第三步: pycharm的Terminal中执行python manage.py makemigrations python manage.py migrate

bug:No module named ‘MySQLdb’

solution1

用pymysql代替。在项目文件夹下的init.py(settings.py也可以?)添加如下代码即可

1
2
import pymysql
pymysql.install_as_MySQLdb()

solution2
  • step1: 安装mysqlclient, MySQLdb的分叉版本,加入了对python3的支持。mysqlclient下载地址:https://www.lfd.uci.edu/~gohlke/pythonlibs/
  • step2: 下载该文件后在下载文件所在目录运行cmd(或运行cmd后切换到该文件目录下),执行 pip install mysqlclient

python安装libsvm

Posted on 2018-07-12 | In notes.tools

参考 https://blog.csdn.net/rena521/article/details/51187981

从官网下载zip压缩包,在任意目录下解压。

libsvm官网 http://www.csie.ntu.edu.tw/~cjlin/libsvm/

去万能宝库上下载对应版本的.whl文件

http://www.lfd.uci.edu/~gohlke/pythonlibs/
LIBSVM, a library for Support Vector Machines.
libsvm‑3.22‑cp27‑cp27m‑win32.whl
libsvm‑3.22‑cp27‑cp27m‑win_amd64.whl
libsvm‑3.22‑cp34‑cp34m‑win32.whl
libsvm‑3.22‑cp34‑cp34m‑win_amd64.whl
libsvm‑3.22‑cp35‑cp35m‑win32.whl
libsvm‑3.22‑cp35‑cp35m‑win_amd64.whl
libsvm‑3.22‑cp36‑cp36m‑win32.whl
libsvm‑3.22‑cp36‑cp36m‑win_amd64.whl
libsvm‑3.22‑cp37‑cp37m‑win32.whl
libsvm‑3.22‑cp37‑cp37m‑win_amd64.whl

cp后的数字表示python版本,win32为32位机,win_amd64为64位机。这里机器的版本号指安装的python版本号。否则报错
xxx.whl is not supported wheel on this platform

参考解决方法 https://stackoverflow.com/questions/28568070/filename-whl-is-not-supported-wheel-on-this-platform

可能原因:

  • python版本号不对,cp后的数字表示python版本,查看python版本命令:python —version
  • pip版本落后。 更新pip版本命令:python -m pip install —upgrade pip
  • amd64指Python版本而非Windows版本。

查看方法:

  • 运行cmd,命令python -v
  • 运行cmd, 命令python
  • 运行cmd, 命令python。

    import platform
    platform.architecture()

安装.whl文件

命令 pip install ....\libsvm-3.21-cp27-none-win32.whl #..为.whl文件的存放路径

python安装目录下的Lib\site-packages文件夹中,有一个\libsvm-3.21.dist-info文件

复制Lib目录下的libsvm.dll,替换掉step1中解压包中windows目录下的libsvm.dll文件。

python3字典排序

Posted on 2018-07-09 | In notes.code
1
2
3
4
5
6
7
8
9
10

def sort_dict(dict_words):
keys = dict_words.keys()
values = dict_words.values()
list_one = [(key, val) for key, val in zip(keys, values)]
list_sort_value_desc = sorted(list_one, key=lambda x: x[1], reverse=True) # 按照第一个元素(value)降序排列
# list_sort_value_asc = sorted(list_one, key=lambda x: x[1], reverse=False) # 按照第一个元素(value)升序排列
# list_sort_key_desc = sorted(list_one, key=lambda x: x[0], reverse=True) # 按照第0个元素(key)降序排列
# list_sort_key_asc = sorted(list_one, key=lambda x: x[0], reverse=False) # 按照第0个元素(key)升序
return list_sort_value_desc
123…5

Sayarara

42 posts
9 categories
36 tags
© 2019 Sayarara
Powered by Hexo
|
Theme — NexT.Muse v5.1.4