python DL/ML 相关指令

1.try...exception中不要在exception中用if不会执行

2.python3 读取中文文档

import codecs
f = codecs.open('mix.label.scp', 'r+', encoding='utf-8')

3.csv文件按行写入并去除空行

import csv
with open('length_distribution.csv', 'w', newline='') as csvfile:
    writer = csv.writer(csvfile)
    
    writer.writerow(['length', 'frequent'])
    
    for i, (length, frequent) in enumerate(recounted):
        writer.writerow([length, frequent])

4.统计list中元素出现频率并按key的大小进行排序

from collections import Counter
recounted = Counter(length_list)
recounted = sorted(recounted.items(), key= lambda recounted:recounted[0])

5.判断一个字符是英文还是中文还是数字

import string
if u'\u4e00' <= sentences[0][0] <= u'\u9fff':
    print('Chinese')
if display_text_input[k] in string.ascii_letters or display_text_input[k].isdigit():
     text_label[k] = 1

6.多线程

import concurrent.futures
with concurrent.futures.ProcessPoolExecutor() as executor:
        executor.map(get_val_result, sample_list)

7.文件复制

import shutil
shutil.copy(img_path,target_path )

8.统计numpy矩阵中单个元素的数量

np.sum( ndarray == 1 )

9.线程设置

设置:export OMP_NUM_THREADS=8

查看单个变量:echo $OMP_NUM_THREADS
查看全部变量:export

删除:unset OMP_NUM_THREADS

10.任务转后台生成日志

nohup ./train.sh>>trst.log 2>&1 &

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值