好用的函数,assert,random.sample,seaborn tsplot, tensorflow.python.platform flags 等,持续更新

python 中好用的函数,random.sample等,持续更新

random.sample

   random.sample的函数原型为:random.sample(sequence, k),从指定序列中随机获取指定长度的片断。sample函数不会修改原有序列

import random
list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
slice = random.sample(list, 5)  # 从list中随机获取5个元素,作为一个片断返回
print(slice)
print(list)# 原有序列并没有改变
[1, 8, 7, 6, 4]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

 

 

seaborn tsplot

学习参考链接:官方说明博客总结

Pandas的DataFrame常常和tsplot搭配使用,DataFrame的用法以及构造数组的具体例子参考博客

最简单的时序折线图绘制见参考例子。更多关于参数unit,direction,time的使用暂时还没有弄明白,后续补充。

和plot相比最大的好处就是可以画出平均线,比如对比两种方法的性能,每一种方法有100条结果,用tsplot可以直观对比平均线。

 tensorflow.python.platform flags 标志的使用

学习参考链接:tensorflow命令行参数原理详细解析以及实例

python assert的作用

学习参考链接:python assert的作用简单的例子

python dir(对象)

 dir() 是一个内置函数,用于列出对象的所有属性及方法。

reuse_variables()的用法

参考莫凡python,以及下列示意性代码

 with tf.variable_scope('model', reuse=None) as training_scope:
    print(dir(self))
    if 'weights' in dir(self):
        training_scope.reuse_variables()
        weights = self.weights
    else:
        # Define the weights
        self.weights = weights = self.construct_weights()

 tf.assign()、tf.assign_add()的用法

 
原文地址:https://www.cnblogs.com/luckyscarlett/p/10551467.html