1.np.arange()
函数返回一个有终点和起点的固定步长的排列,如[1,2,3,4,5],起点是1,终点是5,步长为1。
7.time = np.linspace(0, 10, 2000)
0-10生成2000个数
2.np.where(condition, x, y)
满足条件(condition),输出x,不满足输出y。
3.np.lexsort
lexsort支持对数组按指定行或列的顺序排序
以免浅拷贝:
>>> lists = [[] for i in range(3)]
>>> lists[0].append(3)
>>> lists[1].append(5)
>>> lists[2].append(7)
>>> lists
[[3], [5], [7]]
二维数组创建方式为:
myList = [([0] * 3) for i in range(4)]
5.np.full(shape, fill_value)
可以生成一个元素为fill_value,形状为shape的array
6.计时器
import time
time_start=time.time()
for i in range(10):
print(i)
time_end=time.time()
print('totally cost',time_end-time_start)
对二维数组
—— np.where()[0] 表示行的索引;
—— np.where()[1] 则表示列的索引
7. np.argsort 返回从小到大顺序的索引列表
8. 主函数的设置
def main():
ph = loadmat('detrend_ph')
h2p = loadmat('h2p_se')
dem_error, max_corr, ph_correct = ica_dem_error_single_2019(ph, h2p)
if __name__=='__main__':
main()
9.存储.mat文件
import scipy.io as scio
from scipy.io import savemat
aL = detrend_ph.conj().T
bB = h2p_se
scio.savemat('aL.mat', {'aL':aL})
scio.savemat('bB.mat', {'bB':bB})
加载.mat文件
from scipy.io import loadmat
h2p = loadmat("h2p_se.mat")["h2p_se"]
ph = loadmat("detrend_ph.mat")["detrend_ph"]
Ndim,NPS = np.shape(ph)
10.数组行向量转换成列向量
a = np.array([x for x in range (5)])
print(a.shape)
print(a)
a = a[:,np.newaxis]
print(a)
13. str.lower()
Python lower() 方法转换字符串中所有大写字符为小写。
6.del a 删除变量a
2. 注意:一维数组转置仍为一维数组。可用[:,np.newaxis]转为列向量
3. 可遍历的数据类型:列表,元组,字符串