このメソッドは,要素が 1 の配列を生成します.
引数は「ones(shape[, dtype, order])」です.shape: 配列の形を表す整数やリスト,タプルです.dtype: データの型 (default folat64) です.order: データの格納方法 ('C': row-major C-style default, 'F': column-major Fortran-style) を示します.通常,order は指定する必要はありません.
戻り値は,Numpy の ndarray です.
import numpy as np a = np.ones(6) b = np.ones((2,3)) c = np.ones((2,2,2), dtype=np.int) d = np.ones([3,2], dtype=np.int) print('a = ', a, '\n') print('b = ', b, '\n') print('c = ', c, '\n') print('d = ', d, '\n')
a = [ 1. 1. 1. 1. 1. 1.]
b = [[ 1. 1. 1.]
[ 1. 1. 1.]]
c = [[[1 1]
[1 1]]
[[1 1]
[1 1]]]
d = [[1 1]
[1 1]
[1 1]]