zoukankan      html  css  js  c++  java
  • daily work note

    1. Gfile

    Definition: A Python interface to the Google file layer. It allows you to interact with any Google file (GFS, local, etc.) using familiar Python file methods.

    a. tf.gfile.Glob(filename): 查找匹配pattern的文件并以列表的形式返回,filename可以是一个具体的文件名,也可以是包含通配符的正则表达式

    b. tf.io.gfile.listdir(path) 返回目录中包含的条目列表

    c. tf.gfile.IsDirectory(dirname)返回路径是否为目录

    2. raw_input() 直接读取控制台的输入

    3. 密钥

    a) 操作系统中的随机数产生器

    >>> import os

    >>> salt = os.urandom(32)

    Return a string of 32 random bytes suitable for cryptographic use.

    b) 使用Fernet产生密钥的两种方式

    b.1  调用key = Fernet.generate_key()

    def generate_key(cls):

            return base64.urlsafe_b64encode(os.urandom(32))

    b.2  设定一个password,接着使用PBKDF2HMAC。它是个密钥推导函数,通过多次对salt进行hash运算从而产生密钥。通过密钥推导函数,输出32位随机数,使用key = base64.urlsafe_b64encode(kdf.derive(password))产生Fernet使用的密钥。

    >>> import base64

    >>> import os

    >>> from cryptography.fernet import Fernet

    >>> from cryptography.hazmat.backends import default_backend

    >>> from cryptography.hazmat.primitives import hashes

    >>> from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC

    >>> password = b"password"

    >>> salt = os.urandom(16)

    >>> kdf = PBKDF2HMAC(

            algorithm=hashes.SHA256(),

            length=32,

            salt=salt,

            iterations=100000,

            backend=default_backend()

        )

    >>> key = base64.urlsafe_b64encode(kdf.derive(password))

    >>> f = Fernet(key)

    >>> token = f.encrypt(b"Secret message!")

    >>> token

    '...'

    >>> f.decrypt(token)

    'Secret message!

    4. python json.dumps() json.dump()的区别

    dumps是将dict转化成str格式,loads是将str转化成dict格式。dump和load也是类似的功能,只是与文件操作结合起来了

    5. Unzip via unzip '*.zip' under terminal

    6. from shapely.geometry import shape

    object.buffer(distance, resolution=16, cap_style=1, join_style=1, mitre_limit=5.0, single_sided=False)

    • Returns an approximate representation of all points within a given distance of this geometric object. The styles of caps are specified by integer values: 1 (round), 2 (flat), 3 (square). These values are also enumerated by the object shapely.geometry.CAP_STYLE.

    • The styles of joins between offset segments are specified by integer values: 1 (round), 2 (mitre), and 3 (bevel). These values are also enumerated by the object shapely.geometry.JOIN_STYLE.

    • A positive distance has an effect of dilation; a negative distance, erosion. The optional resolution argument determines the number of segments used to approximate a quarter circle around a point.

    # Dilation of a line (left) and erosion of a polygon (right). New object is shown in blue.

    7. Neural network(layered representation of data, which means data transfered to different layers) --> ML(figure out the rules itself) --> AI(computer代替人类)

    8. In TensorFlow, we got feature as input, label as output (models will help us with it)

    9. ML分为Supervised,Unsupervised以及Reinforcement。Reinforcement set rewarding rules,并力求分数最大化

    10. PIL中Image与Numpy中array相互转换

    array-->image: Image.fromarray(np.unit8(img))

    image-->array: img = np.asarray(image)

    若出现read- only的错误,一般是‘r',‘rb‘的问题

    修正:img.flags.writeable = True

    11. numpy.squeeze() 去掉shape为1的维度

    举例:tensor( [ [ [ 0, 1, 2 ] , [ 3, 4, 5 ] ] ] ) 经过squeeze变为tensor( [ [ 0, 1, 2 ] , [ 3, 4, 5 ] ] )

    12. false color假色

    In this image, colors have been assighed to 3 different wavelengths that our eyes cannot normally see

    在项目中,由于原图片为黑白的,我们添加false color以增加美观度

    13. np.argsort()

    将矩阵按要求排序,返回排序后的下标

    14. perspective transformation

    将成像投影到一个新的视平面,也称投影映射

    15. WGS 84与Web Mercator的转变

    a. WGS84 --> Web Mercator

    x = lon * 20037508.34/180

    y = log(tan((90+lat)*PI/360))/(PI/360)*20037508.34/180

    lon经度;lat纬度

    16. projected coordinate system: tells the data how to draw on a flat surface

    GCS (G-Geographic): where the data is located on the earth's surface

    17. S^2 Geometry(S^2为球体数学符号)

    1)主要用于球体几何而非平面2D,适合用于地理数据

    2)传统制图基于map projection,将地球表面的点映射到平面地图上,误差较大。S2将地球表面上的点映射到一个完美的数学球体

    不映射到椭球体上的原因:速度+鲁棒性

    3)S2 library定义了一个框架,用于将单位球体分解为单元格的层次结构,每个单元格都是一个四边形,最外层通过将立方体的六个面投影到单位球体上获得,然后将外层单元格递归的细分成四个子集

    4)层次结构中的每个单元格都有一个级别

    Defined as the number of times the cell has been subdivided

    18. API sandbox: 一种特殊环境,测试人员用以模拟生产环境的特征,并从应用程序依赖的所有API中创建模拟响应

    19. DataFrame是一个表格型的数据结构,它含有一组有序的列,每列可以是不同的值类型(数值、字符串、布尔型值)。DataFrame 既有行索引也有列索引,它可以被看做由 Series 组成的字典(共同用一个索引),构造方法如下:

    pandas.DataFrame( data, index, columns, dtype, copy)

    20. pandas.concat()通常用来连接DataFrame对象。默认情况下是对两个DataFrame对象进行纵向连接, 通过设置参数也可以实现DataFrame对象的横向连接(如果希望重新设置合并之后的DataFrame对象的index值, 可以添加ignore_index=True参数)

    21. lambda

    lambda:输入是传入到参数列表x的值,输出是根据表达式计算得到的值。
    比如:lambda x, y: xy  #函数输入是x和y,输出是它们的积xy
    lambda x :x[-2:]  #x是字符串时,输出字符串的后两位

    当想让方程作用在一维的向量上时(既可以作用于一行或者一列的元素,也可以作用于单个元素),可以使用apply来完成,常常与lambda合用,如下所示

    修改某列的字符,只保留后两位
    df[‘time’]=df[‘time’].apply(lambda x :x[-2:])

     
  • 相关阅读:
    手写Promise(转)
    阻止element组件中的<el-input/>的粘贴功能(转)
    js 对象深拷贝函数
    20182301 2019-2020-1《程序设计与数据结构》课程总结
    20182301 2019-2020-1 《数据结构与面向对象程序设计》实验9报告
    团队博客第二周——DIG
    20182301 2019-2020-1 《数据结构与面向对象程序设计》第十周学习总结
    《团队作业第一周》团队作业——DIG
    20182301 2019-2020-1 《数据结构与面向对象程序设计》哈夫曼实验报告
    20182301 2019-2020-1 《数据结构与面向对象程序设计》第9周学习总结
  • 原文地址:https://www.cnblogs.com/eleni/p/15572988.html
Copyright © 2011-2022 走看看