亿些函数

Numpy

np.percentile

计算一个多维数组的任意百分比分位数,此处的百分位是从小到大排列。(如四分位数)

np.percentile(a, q, axis=None, out=None, overwrite_input=False, interpolation='linear', keepdims=False)

np.percentile(a, q, axis=None, out=None, overwrite_input=False, interpolation='linear', keepdims=False)
 
a : array,用来算分位数的对象,可以是多维的数组
q : 介于0-100float,用来计算是几分位的参数,如四分之一位就是25,如要算两个位置的数就(25,75)
axis : 坐标轴的方向,一维的就不用考虑了,多维的就用这个调整计算的维度方向,取值范围0/1
out : 输出数据的存放对象,参数要与预期输出有相同的形状和缓冲区长度
overwrite_input : bool,默认False,为True时及计算直接在数组内存计算,计算后原数组无法保存
interpolation : 取值范围{'linear', 'lower', 'higher', 'midpoint', 'nearest'}
            默认liner,比如取中位数,但是中位数有两个数字67,选不同参数来调整输出
keepdims : bool,默认False,为真时取中位数的那个轴将保留在结果中

>>>a = np.array([[10, 7, 4], [3, 2, 1]])
>>>a
array([[10,  7,  4],
       [ 3,  2,  1]])
>>>np.percentile(a, 50)
3.5
>>>np.percentile(a, 50, axis=0)
array([[ 6.5,  4.5,  2.5]])
>>>np.percentile(a, 50, axis=1)
array([ 7.,  2.])
>>>np.percentile(a, 50, axis=1, keepdims=True)
array([[ 7.],
       [ 2.]])

np.random.choice()

https://blog.csdn.net/ImwaterP/article/details/96282230

Python内置

glob.glob

匹配所有的符合条件的文件,并将其以list的形式返回。(子目录也算)

str()、repr()的区别,eval() 函数

eval() 函数用来执行一个字符串表达式,并返回表达式的值。
str()函数:将值转化为适于人阅读的字符串的形式
repr()函数:将值转化为供解释器读取的字符串形式,外层会多一对引号,这一特性有时候在eval操作时特别有用。
https://blog.csdn.net/kongsuhongbaby/article/details/87398394

import tensorflow as tf
rnn_cells = {
    "LSTM": tf.contrib.rnn.LSTMCell,
    "GRU": tf.contrib.rnn.GRUCell,
    "BasicRNN": tf.contrib.rnn.BasicRNNCell,
    "LayerNormBasicLSTM": tf.contrib.rnn.LayerNormBasicLSTMCell,
}
cell_type_str = repr(rnn_cells['BasicRNN']).split('.')[-1]
print(cell_type_str)
结果:
BasicRNNCell'>
--------------------------------------------
import numpy as np
import tensorflow as tf
rnn_cells = {
    "LSTM": tf.contrib.rnn.LSTMCell,
    "numpy": np.random.randn(2,3),
}
cell_type_str = repr(rnn_cells['LSTM'])
cell_type_str1 = repr(rnn_cells['numpy'])
print(cell_type_str)
print(cell_type_str1)
结果:
<class 'tensorflow.python.ops.rnn_cell_impl.LSTMCell'>
array([[-0.66323427, -0.22806648, -0.02021589],
       [ 0.2954924 , -1.25333128, -0.21879271]])

call()

http://c.biancheng.net/view/2380.html
https://www.cnblogs.com/xinglejun/p/10129823.html
该方法的功能类似于在类中重载 () 运算符,使得类实例对象可以像调用普通函数那样,以“对象名()”的形式使用。
class CLanguage:
# 定义__call__方法
def call(self,name,add):
print(“调用__call__()方法”,name,add)

clangs = CLanguage()
clangs(“C语言中文网”,“http://c.biancheng.net”)
====
程序执行结果为:
调用__call__()方法 C语言中文网 http://c.biancheng.net

random_state

随机数种子——其实就是该组随机数的编号,在需要重复试验的时候,保证得到一组一样的随机数。
random_state的取值范围为0-2^32。当random_state=None时,可以理解为随机分配一个整数给random_state,这样就导致每次运行的结果都可能不同。

str.join(sequence)

将序列中(sequence)的元素以指定的字符(str)连接生成一个新的字符串。

def correct_sentence(text: str) -> str:

这是python3的函数注释,暗示传入参数的数据类型,提高可读性。
text: str 函数参数注释,参数text建议传入字符串(str)数据类型
-> str - >是返回值注释的标记,建议函数返回值数据类型为字符串(str)
:冒号 最后的冒号是声明函数必带的标记

copy文件

os.system()找不到解决办法
使用了import shutil
shutil.copy(filename1, filename2)

python3.6 f’ {x}’

  • " %s" %name
  • " {}".format()
    https://www.cnblogs.com/c-x-a/p/9333826.html

re.sub

https://blog.csdn.net/jackandsnow/article/details/103885422
https://www.jb51.net/article/170226.htm

>>> s1 = re.sub(r'[^A-Za-z ]+', ' ', s)
>>> s1
' I  m so glad to introduce myself  and I m   years old    Today is   It is a wonderful DAY   HHHHello ComeHere AA zz http welcome cn'
>>> re.sub(r'[ ]+', ' ', s1)
' I m so glad to introduce myself and I m years old Today is It is a wonderful DAY HHHHello ComeHere AA zz http welcome cn'

进阶re.sub()中的 r’\1\2\3\数字’
https://blog.csdn.net/weixin_45231460/article/details/104389223
其实代表的就是group(1)和group(2),既然中间的参数是准备替换的字符串,那我们同样可以引用已经匹配出来的字符串

正则表达式:https://www.runoob.com/python/python-reg-expressions.html

编码

Unicode 和 UTF-8 的关系
在读取文件中出现\ufeff

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值