Numpy-resize

提供:Dev Guides
移動先:案内検索

numpy.resize

この関数は、指定されたサイズの新しい配列を返します。 新しいサイズが元のサイズよりも大きい場合、元のエントリの繰り返しコピーが含まれます。 この関数は、次のパラメーターを取ります。

numpy.resize(arr, shape)

どこで、

Sr.No. Parameter & Description
1

arr

サイズ変更する入力配列

2

shape

結果の配列の新しい形状

import numpy as np
a = np.array([[print 'First array:'
print a
print '\n'

print 'The shape of first array:'
print a.shape
print '\n'
b = np.resize(a, (3,2))

print 'Second array:'
print b
print '\n'

print 'The shape of second array:'
print b.shape
print '\n'
# Observe that first row of a is repeated in b since size is bigger

print 'Resize the second array:'
b = np.resize(a,(3,3))
print b

上記のプログラムは、次の出力を生成します-

First array:
[[The shape of first array:
(2, 3)

Second array:
[[The shape of second array:
(3, 2)

Resize the second array:
[[