Python Numpy配列の要素の末尾からn個の要素を取得するサンプル

環境
Windows 11 Pro 64bit
Python 3.11

構文
変数名 = array[-n:]
n 取得する要素数
配列(Array)の最後からn個の要素を取得します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import numpy as np
numbers = np.array([13, 42, 63, 764, 85,86])
res = numbers[-4:]
print(res)
import numpy as np numbers = np.array([13, 42, 63, 764, 85,86]) res = numbers[-4:] print(res)
import numpy as np

numbers = np.array([13, 42, 63, 764, 85,86])

res = numbers[-4:]

print(res)

実行結果
[ 63 764 85 86]

Python

Posted by arkgame