parameter.py 文件源码

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

项目:flopymetascript 作者: bdestombe 项目源码 文件源码
def parse_array_str(ar, orig_shape, compres, precision=8):
        """
        -1: unable to reduce in size
        0:  a value in a singleton dimension may be used
        1:  broadcastable array

        todo:
        for multiline array strings add extra space in line 2, 3..
        use array2string-prefix for this
        """

        max_line_width = np.inf
        suppress_small = True  # to mask some rounding issues
        np.set_printoptions(threshold=np.inf, linewidth=np.inf)

        if compres == 0:
            return str(ar)

        elif compres == -1:
            pre = 'np.array('
            post = ')'
            ar_str = np.array2string(
                np.array(ar),
                max_line_width=max_line_width,
                precision=precision,
                suppress_small=suppress_small,
                separator=',',
                prefix=pre)
            ar_str = ' '.join(ar_str.split())
            return pre + ar_str + post

        elif compres == 1:
            pre = 'np.broadcast_to('
            post = ', {0})'.format(orig_shape)
            ar_str = np.array2string(
                ar,
                max_line_width=max_line_width,
                precision=precision,
                suppress_small=suppress_small,
                separator=',',
                prefix=pre)
            ar_str = ' '.join(ar_str.split())
            return pre + ar_str + post
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号