2019-01-19 'helpers';ra

2019-01-19  本文已影响1人  七月那个阿瓜呀

1. 问题解决ModuleNotFoundError: No module named 'helpers'

pip install https://github.com/dianakhuang/pytumblr/archive/diana/python-3-support.zip

2. random_sequences 函数

功能 生成一批随机序列,序列长度 [length_from, length_to],数值大小 [vocab_lower, vocab_upper]

def random_sequences(length_from, length_to,
                     vocab_lower, vocab_upper,
                     batch_size):
    """ Generates batches of random integer sequences,
        sequence length in [length_from, length_to],
        vocabulary in [vocab_lower, vocab_upper]
    """
    if length_from > length_to:
            raise ValueError('length_from > length_to')

    def random_length():
        if length_from == length_to:
            return length_from
        return np.random.randint(length_from, length_to + 1)

    while True:
        yield [
            np.random.randint(low=vocab_lower,
                              high=vocab_upper,
                              size=random_length()).tolist()
            for _ in range(batch_size)
        ]
  1. axis
    numpy当中axis的值表示的是这个多维数组维度的下标,比如有一个二维数组a,a的shape是(5,6),也就是说a有5行6列,axis=0表示的就是[5,6]中的第一个维度,也就是axis=1表示的是[5,6]中的第二个维度,也就是
import numpy as np
a = np.array([[6,2,7],[4,6,5]])
# b表示沿着axis=0(行)这条轴取max,得到的结果就是把输入数组的'行'给消除了,2行变1行
b = a.max(axis=0)
print (b)
print (b.shape)

输出:
[6 6 7]
(3,)

# c表示沿着axis=1(列)这条轴取max,得到的结果就是把输入数组的'列'给消除了,3列变1列
c = a.max(axis=1)
print (c)
print (c.shape)

输出:
[7 6]
(2,)

上一篇下一篇

猜你喜欢

热点阅读