ravelとreshapeの違いは何なのでしょうか?
例えば、bという配列があったとき
b.ravel
と
b.reshape(-1)
が配列の軸を取り除く働きをし、等価な役割をする、と勉強しました。
しかし、本当に等価な役割をするなら、なぜ同じ役割のものが2つ用意されているのでしょうか?
何かちがいはあるのでしょうか?
# coding: utf-8 from __future__ import absolute_import from __future__ import division from __future__ import print_function import os import numpy as np a = np.arange(5) print(a) print(a.shape) a = a[np.newaxis,:,np.newaxis] print(a) print(a.shape) b = np.arange(12).reshape((3,4)) print(b) print(b.ravel) print(b.reshape(-1))
とコードを書くと
print(b.ravel)
print(b.reshape(-1))
は
<built-in method ravel of numpy.ndarray object at 0x1031c6760> [ 0 1 2 3 4 5 6 7 8 9 10 11]
と出力されました。
b.ravelがオブジェクト型で返し、b.reshape(-1)はリスト型で返す、ということでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。