0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[py2rb] len(np.array(...).shape)

Posted at

はじめに

移植やってます。
( from python 3.7 to ruby 2.7 )

numpy (Python)

len(np.array(x).shape)

配列の次元を取得します。

どうすRuby

np.array(x).shape.size

NoMethodError: undefined method `size' for (3, 2):PyCall::Tuple

lenだからsizeと単純に変換するとエラーになります。
PyCallでは、Rubyで直接取り扱えないオブジェクト?を@__pyptr__として保持します。

np.array(x).shape.to_a.size

np.array(x).mean(axis: 0).to_a # mean:平均 の例

したがって必要に応じた変換を行います。

メモ

  • Python の numpy を学習した
  • 百里を行く者は九十里を半ばとす
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?