NumPy:【データ型】確認方法と実行結果


サマリ

  • dtype
    • 格納されているデータ型確認
  • type
    • 格納している箱(変数)のデータ型確認

前提

サンプルコード

int64

import numpy as np
a = np.array([1, 2])
print(a.dtype)
print(type(a))
int64
<class 'numpy.ndarray'="">
  • dtype
    • 中身を確認する
    • int64…整数
  • type
    • 箱(変数自体)を確認する
    • ndarray(NumPy配列)

float64

import numpy as np
a = np.array([1., 2.])
print(a.dtype)
print(type(a))
float64
<class 'numpy.ndarray'="">
  • dtype
    • 中身を確認する
    • float64…浮動小数点
  • type
    • 箱(変数自体)を確認する
    • ndarray(NumPy配列)

<U1(文字列)

import numpy as np
a = np.array(['a', 'b'])
print(a.dtype)
print(type(a))
<U1
<class 'numpy.ndarray'>
  • dtype
    • 中身を確認する
    • U1…文字列
  • type
    • 箱(変数自体)を確認する
    • ndarray(NumPy配列)


Posted by futa