- 目前实验室中使用更多的是python和matlab,以及少数同学使用C语言
- python在深度学习和科学计算方面有较大优势,而且开源的社区可以非常快速地推动语言的进步,符合社区的需求。IDE推荐:VScode(自定义,自定义,还是自定义!),Cursor(冉冉升起的new choice),pycharm(全家桶,很多需要的功能都已集成好,就像一个matlab)。
- matlab是在python之前进行科学计算的不二之选(可以看到很多老的物理仿真都是通过matlab实现的),但由于其闭源的社区特性,更新速度不如python。我目前基本只会使用matlab进行绘图,其可交互的科学绘图编辑还是更优于python的任何一个第三方包的。
- C语言,编译以后运行速度快,如果要把程序落地做到FPGA驱动的相机上,是必须的。
-
基础内容(仅列举需要重视的知识点,具体内容需要自己查漏补缺)
- syntax、variables、strings、numbers(注意数值位数的区别)、booleans、constants、type conversion
-
操作数
- comparison(>[=], <[=], ==),logical运算(and, or, not)
-
控制流
- if ... elif ... else statement
- for loop with range()/enumerate()/list()
- while —— execute a code block as long as a condition is True
- break, continue and pass
for index in range(n): # more code here if condition: continue / break else: pass
-
函数
- def ...() to make a function
- default parameters and keyword arguments
- recursive functions
- lambda expressions
- docstrings with """ (string) """
def add(a, b): "Return the sum of two arguments" return a + b
>>> help(add) add(a, b) Return the sum of two arguments - *args and **kwargs 当函数需要传入不确定的参数时,需要用到这两个内容。多用于子类继承父类的成员函数中
-
列表
- list python中最常用的数据结构
a = list([1, 2, 3]), a.k.a, [1, 2, 3]
- tuple 内容不变的list
- sort a list (in place) with sorted() (sort())
sorted(list) # 生成一个新的list list.sort() # 在原有的list地址上进行inplace操作
- slice the list
- unpack the list
- iterate over a list
- find the index of an element
a = ['1', '2', '3'] print(a.index('2')) # output: 1
- iterable, 与控制流中的for循环相同
- 元素变换方法map(func, list) / 元素滤波方法 filter(func, list) / 元素合并方法 reduce()
def double(a): return a * 2 a = [1, 2, 3] a_double = map(double, a) # output: [2, 4, 6] a_larger = filter(lambda x: x>1, a) # output: [2, 3] def sum(a, b): return a+b a_reduce = functools.reduce(sum, a) # output: 6 (1+2+3)
- list python中最常用的数据结构
-
字典
- dict 和list一样,也是一种数据结构,通过键值keys进行索引
- 使用enumerate进行遍历的方法
-
集合
- set (不常用,可以不了解)
-
异常处理
- try ... except 用于处理大型程序中有可能会崩的情况、数值计算出Nan的情况等等
try: # code that may cause an exception except ValueError as error: # code to handle the exception
- assume 用于check部分运算的关键节点
- try ... except 用于处理大型程序中有可能会崩的情况、数值计算出Nan的情况等等
-
常用的包以及第三方包
- import 希望能区别你的import到底import了什么?python文件?module?function?
- 通过sys module来check import的路径
- os, time, math, numpy, opencv-python (cv2), pytorch, tensorflow, jax...
-
调试
- jupyter notebook
- ipython with # %% (如果你比较适应逐步调试,随时监视变量的话)
- python内置的time module (如果你敲代码够快,小的问题可以直接用time.sleep调试)