stream.py 文件源码

python
阅读 52 收藏 0 点赞 0 评论 0

项目:Auspex 作者: BBN-Q 项目源码 文件源码
def cartesian(arrays, out=None, dtype='f'):
    """http://stackoverflow.com/questions/28684492/numpy-equivalent-of-itertools-product"""

    arrays = [np.asarray(x) for x in arrays]
    # dtype = arrays[0].dtype

    n = np.prod([x.size for x in arrays])
    if out is None:
        out = np.zeros([n, len(arrays)], dtype=dtype)

    m = int(n / arrays[0].size)
    out[:,0] = np.repeat(arrays[0], m)
    if arrays[1:]:
        cartesian(arrays[1:], out=out[0:m,1:])
        for j in range(1, arrays[0].size):
            out[j*m:(j+1)*m,1:] = out[0:m,1:]
    return out
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号