旅行好きなソフトエンジニアの備忘録

プログラミングや技術関連のメモを始めました

【Python】How to replace items that satisfy a condition without affecting the original array? - 101 Numpy Exercises

Q:

0~9の奇数を元の変数に影響を与えずに-1に変更する

A:

import numpy as np

arr = np.arange(0, 10)
arr_ = np.where(arr%2 == 1, -1, arr)


www.machinelearningplus.com