基础部分之numpy 调整数组维度 resize

调整数组维度 resize

用法

resize(numpy.ndarray, axes=[])
axes: 必须参数,修改维度,给出每个维度的长度

实例:IPython 交互

>>> import numpy as np
>>> a = np.arange(16).reshape(2, 8)
>>> a
array([[ 0,  1,  2,  3,  4,  5,  6,  7],
       [ 8,  9, 10, 11, 12, 13, 14, 15]])
>>> np.resize(a, [4,4])
array([[ 0,  1,  2,  3],
       [ 4,  5,  6,  7],
       [ 8,  9, 10, 11],
       [12, 13, 14, 15]])
>>> np.resize(a, [2,2,4])
array([[[ 0,  1,  2,  3],
        [ 4,  5,  6,  7]],
       [[ 8,  9, 10, 11],
        [12, 13, 14, 15]]])
posted @ 2022-09-18 01:45  流水自净  阅读(162)  评论(0编辑  收藏  举报