
Python
norsd
这个作者很懒,什么都没留下…
展开
-
VCode Python 设置当前目录
随后其中有文件 c:\PythonProjects\SubFoloder\Test.py。例如我打开了Foloder: c:\PythonProjects。在VSCode中打开Folder时,当前目录就是这个Folder。不是 c:\PythonProjects\SubFoloder。而是: c:\PythonProjects。Test.py的当前目录。2.设置新的当前目录。而不是其中文件的目录。运行Test.py,原创 2023-01-27 13:47:10 · 825 阅读 · 1 评论 -
Numpy 操作矩阵
复制矩阵m2 = m1.copym2 = m1[:,:]复制矩阵的部分Rowm[1:] #取第1行之后所有m[-2:] #取最后第2行之后所有(最后第2行和最后第1行)m[1:3] #取第1行到第3行之前(不包括第3行)m[3:-1] #取第3行到最后1行之前(不包括最后1行)m[:-1] #取第0行到最后1行之前(不包括最后1行)需要补充的是,上面的操作,返回的是二维矩阵, shape是2维数组,例如:[3,1]还有一种"取单行"的方.原创 2022-04-03 17:00:20 · 2661 阅读 · 0 评论 -
VSCODE 改变Python版本到3.10
安装Python3.10, 确定Path中有指向新版本文件夹的路劲,同时去除老版本文件夹路径VSCode Setting/User/Extensions/Python/Default Interpreter Path注意是User不是WorkSpace点击VSCode窗体左下角的Python 3.9 xxxx 这个位置后, VSCode 正上方会有下拉框给你选择新的Python解释器我因为已经升级到了3.10,所以图片上没有显示3.9更新Terminal,(此时Termin..原创 2021-11-21 15:22:14 · 10783 阅读 · 0 评论 -
Python min/max 返回index
Reference:https://stackoverflow.com/questions/2474015/getting-the-index-of-the-returned-max-or-min-item-using-max-min-on-a-listvalues = [3,6,1,5]index_min = min(range(len(values)), key=values.__getitem__)values.getitem 这个函数有一个int参数。min(序列数组, key = la原创 2021-11-20 13:08:25 · 1993 阅读 · 0 评论 -
VSCODE 打开多窗口
Ctrl Shift Pref: https://stackoverflow.com/questions/49707703/open-the-same-directory-twice原创 2021-11-13 03:17:45 · 4104 阅读 · 0 评论 -
Python 类datetime的方法 replace 与 astimezone 区别
astimezone: 改变时区, 例如 utc 时间 为 2021/04/15 17:00:00 改为 北京时间后,则变为 2021/04/16 01:00:00replace(tzinfo = new_timezone_info) 替换时区, 时间数值不会发生变化,例如 utc 时间为 2021/04/15 17:00:00 改为 北京时间 2021/04/15 17:00:00 , 或者 没有timezone 的 datetime实例 可以通过这个函数附上 timezone注意事项:.原创 2021-04-15 17:37:11 · 1161 阅读 · 0 评论 -
VSCode 安装 Python pip 包
VSCode 点击 Ctrl+Shift+`Windows环境输入: python -m pip install matplotlib但是速度会很慢,可以通过清华的镜像 python -m pip install matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simpleReference:https://code.visualstudio.com/docs/python/python-tutorialhttps://blog.youkuaiyun.com.原创 2021-04-15 00:48:53 · 13232 阅读 · 0 评论 -
Python dict 使用
sum 所有 valuesum(d.values())dictionary.get(“bogus”, default_value)此时如果dict 不存在key"bogus",将返回default_valuedictionary.setdefault(‘one’, 3.4)此时如果dict 存在’one’ 则等效于 return dictionary[‘one’]此时如果dict不存在’one’ 则等效于 return (dictionary[‘one’] = 3.4)...原创 2021-01-18 11:36:25 · 161 阅读 · 0 评论 -
Python datetime timezone 各种操作
1.替换timezone,不会改变时间datetimeInstance.replace(tzinfo=timezone.utc)2.创建本地timezonezoneLocal = dateutil.tz.tzlocal()3.调整时区datetimeInstance.astimezone(tz=timezone.utc)原创 2021-01-18 11:17:15 · 1607 阅读 · 0 评论 -
Python List 对象的 append 和 extend 的区别
1.append: Appends object at end x = [1, 2, 3] x.append([4, 5]) x = [1, 2, 3, [4, 5]]2. extend: Extends list by appending elements from the iterablex = [1, 2, 3]x.extend([4, 5])x = [1, 2, 3,转载 2017-08-03 03:14:29 · 298 阅读 · 0 评论 -
numpy.ndarray 如何转化为 list
vXmn.tolist()[[1,2], [1,2], [3,3],…]vXm1.tolist() [[1], [-1], [1]…]vXm1.reshape((m,)).tolist() [1, -1, 1] p.s: m 来自: (m, n) = vXm1.shape原创 2017-08-09 01:07:41 · 7907 阅读 · 1 评论 -
Python List Comprehension, Dictionary Comprehension
[ x*x for x in range(5)]{i: datas[i] for i in range(len(datas))} {0:”hello”}, {1:”abc”}, …reference: https://stackoverflow.com/questions/14507591/python-dictionary-comprehension转载 2017-08-09 01:05:37 · 810 阅读 · 0 评论 -
nanomsg-python 安装在Windows下的流程
在本机安装x64的nanomsg : https://blog.youkuaiyun.com/norsd/article/details/81285104从GitHub 下载 nanomsg-python的 zip 文件: https://github.com/tonysimpson/nanomsg-python把zip文件解压到 c:\nanomsg-python-master以Administr...原创 2018-07-30 15:02:10 · 1666 阅读 · 0 评论 -
rpy2 使用中注意的问题
import rpy2时 windows抛出 Module 没有找到错误 添加 R_HOME 全局变量 值形如: “C:\Program Files\R\R-3.4.0” 随后重启VisualStudio后再次运行即可原创 2017-06-03 02:25:49 · 866 阅读 · 0 评论 -
numpy.searchsorted 用法
numpy.searchsorted : vs = [1, 3, 5, 7, 9] numpy.searchsorted(vs, 4) output:2我们看到searchsorted 返回了2,注意vs必须是按序排 列,如果是乱序的话可以如此调用: anumpy.searchsorted(vs, 4, sorter = numpy.argsort原创 2017-08-03 04:13:18 · 9129 阅读 · 0 评论 -
numpy mat 与 matrix 函数的区别
Reference: Here简单的说: Tmn = mat(vTmn) 如果vTmn是 matrix或者ndarray则: 此时Tmn和vTmn指向同一个对象而 Tmn = matrix(vTmn) Tmn是一个全新的对象原创 2017-08-13 00:33:11 · 4057 阅读 · 0 评论 -
numpy ndarray 与 array
Reference: Here简单说 numpy.array(…) 作为一个函数, 他返回numpy.ndarray这个class 与numpy.array这个函数同类型的有: numpy.array numpy.zeros numpy.empty同样的, 不建议使用numpy.ndarray(…)创建一个ndarray转载 2017-08-06 16:54:06 · 7244 阅读 · 0 评论 -
Python 问号表达式(ternary conditional operator)的实现
a if condition else bref: https://stackoverflow.com/questions/394809/does-python-have-a-ternary-conditional-operator转载 2018-07-29 19:30:28 · 1277 阅读 · 0 评论 -
Python enum 与 int 之间的转换
class eOperator(enum.Enum): unknown = 0 equal = 1 gt = 2 gte = 3 lt = 4 lte = 5注意千万不要写成:class eOperator(enum.Enum): unknown = 0, equal = 1, gt = 2, .........原创 2018-07-31 23:37:02 · 9963 阅读 · 0 评论 -
Python decorate 函数
1. decorate 函数需要在 "@wrap" 之前定义, 否则会报错原创 2014-03-17 18:50:36 · 1683 阅读 · 0 评论 -
rpy2 的安装
1.第一种方法 ref: https://stackoverflow.com/questions/34512910/error-install-rpy2Download the version you need here http://www.lfd.uci.edu/~gohlke/pythonlibs/#rpy2 Open Anaconda Prompt and navigate to the原创 2017-06-03 02:09:27 · 3114 阅读 · 0 评论 -
Python 将 tuples 作为参数依序传入函数 (Expanding tuples into arguments)
myfun(*tuple) does exactly what you request.reference: http://stackoverflow.com/questions/1993727/expanding-tuples-into-arguments转载 2017-05-07 21:43:07 · 1398 阅读 · 0 评论 -
numpy windows环境下载安装
由于numpy在多个平台下非常流行,以至于习惯WINDOWS环境下原创 2014-11-01 12:51:16 · 27709 阅读 · 2 评论 -
Pycharm 配置autopep8到菜单
Pycharm 可以自动检测PEP8规范。原创 2014-10-02 17:07:13 · 10825 阅读 · 0 评论 -
Python Matplotlib 中对于 bar 显示时间的问题
参考:http://stackoverflow.com/questions/13515471/matplotlib-how-to-prevent-x-axis-labels-from-overlapping-each-other原创 2014-11-11 22:21:25 · 5025 阅读 · 0 评论 -
Matplotlib 在绘画bar时, 鼠标响应点击 bar 的消息
官方教程:http://urania.udea.edu.co/sitios/astronomia-2.0/pages/descargas.rs/files/descargasdt5vi/Cursos/CursosElectivos/FisicaAstrofisicaComputacional/2009-2/Documentacion/matplotlib/examples/event_hand原创 2014-11-11 22:24:45 · 3251 阅读 · 0 评论 -
如何使得 python 脚本 不一闪而过
1. 简单的方法是在最后加上如下语句: os.system("pause")2. 但是这个不一定有用,原因是可能在之前的代码中发生异常,那么我们看到的效果也是直接一闪而过办法是 在语句中加上 try catch如下:__author__ = 'di_shen_sh'# coding=utf8# 上句说明使用utf8编码try: import原创 2014-03-15 16:33:05 · 32356 阅读 · 0 评论 -
python 如何在 command 中能够找到 其他module
部分代码如下:__author__ = 'norsd'# coding=utf8# 上句说明使用utf8编码try: import os import sys import time #关键语句,使得py文件能够找到其他module #关键语句,使得py文件能够双击在外部运行 sys.path.append(os.path.dirname原创 2014-03-15 16:28:38 · 957 阅读 · 0 评论 -
如何利用 任务计划程序 实现计算机重启后运行特定程序(网络方面)
1. 特定程序是一个python的脚本文件,他会向外发送邮件2. 控制面板 -> 管理工具 -> 任务计划程序 -> 菜单:操作->创建任务 然后填写名称,描述,随后在 安全选项中 (我这台服务器是默认administrator) ,选择 “不管用户是否登录都要运行” 和 “使用最高权限运行" 触发器 -> 新建触发器, 选择启动时 , 最下方启用默认打原创 2014-03-15 16:25:15 · 8987 阅读 · 0 评论 -
python matplotlib相关 dateutil
dateutil: easy_install python_dateutilpyparsing: easy_install pyparsing原创 2014-03-02 14:45:15 · 1193 阅读 · 0 评论 -
Python的一些技巧
>>> m = max(a)>>> [i for i, j in enumerate(a) if j == m][9, 12]原创 2014-05-10 00:44:07 · 749 阅读 · 0 评论 -
Python 3.x 的一些注意事项
1. reload 被更改需要 在console执行 from imp import reload 才能调用CT同时,如果py文件是位于主文件夹深部的位置,可以这么做: import ComicTest.ComicTest as CTreload(CT)2. urllib2模块被合并到urllib中http://stackoverflow.com/question原创 2014-11-30 04:24:24 · 705 阅读 · 0 评论 -
Python 读取object中所有方法
[method for method in dir(object) if callable(getattr(object, method))] reference: http://stackoverflow.com/questions/34439/finding-what-methods-an-object-has转载 2017-05-07 21:06:46 · 11469 阅读 · 0 评论 -
Pycharm 设置TextStyle
之前在脚本中选择了一个字符串, PyCharm会“高亮”所有相同的字符串, 但是我不满意这个“高亮”的颜色,因为和背景色太相似了,所以需要做一下操作,修改这个“高亮”颜色值: File–Settings 在Settings对话框的左侧选择 Editor->Colors & Fonts -> General 在Settings对话框的右侧选择: Code -> Identifier un原创 2016-08-12 01:13:12 · 4809 阅读 · 0 评论 -
Python 获取脚本路径以及脚本所在文件夹路径
import os script_path = os.path.realpath(__file__) script_dir = os.path.dirname(script_path)原创 2016-05-30 02:06:58 · 4401 阅读 · 1 评论 -
PyCharm的一些使用技巧
定位到函数定义 在函数名处 Ctrl + B 就会快速定位到函数定义处在Console中执行文件 全选内容后,右键菜单 Execute Selection in Console 或者快捷键 Alt + Shift + E原创 2016-01-20 02:54:34 · 14312 阅读 · 0 评论 -
Matplotlib 如何显示中文
Python 3.x主要是如下代码import osfont = FontProperties(fname=os.path.expandvars(r"%windir%\fonts\simsun.ttc"), size=14)plt.xlabel("测试", fontproperties=font)# coding:utf-8# from __future__ import unicode_li原创 2016-01-27 01:39:05 · 2337 阅读 · 2 评论 -
pip 在windows下的更新升级
1. pip 在 PyCharm 无法自动更新2. https://pip.pypa.io/en/latest/installing.html官方网页要求在 cmd中输入以下命令进行 pip的 更新:python -m pip install -U pip原创 2015-01-31 22:23:49 · 37971 阅读 · 0 评论 -
Ironpython 安装numpy包
http://pytools.codeplex.com/wikipage?title=NumPy%20and%20SciPy%20for%20.Nethttps://www.enthought.com/repo/.iron/1.下载一个ironpkg 这个是ironpython的一个包管理器 其实就是一个py文件2. 输入: ironpkg ironpkg s原创 2013-08-20 21:41:48 · 7696 阅读 · 2 评论