python - 用索引列表替换 3d Numpy 数组的多个值
问题描述
我需要使用索引列表将 3d NumPy 数组的多个值替换为其他值。例如:
old_array = np.full((224,224,3),10)
# in below list first position element are indexes and 2nd one are their corresponding values
list_idx_val = [[array([[ 2, 14, 0],
[ 2, 14, 1],
[ 2, 14, 2],
[99, 59, 1],
[99, 61, 1],
[99, 61, 2]], dtype=uint8), array([175, 168, 166,119, 117, 119], dtype=uint8)]
#need to do
old_array[2,14,1] =168
一种方法是简单地访问索引值并用新值替换旧值。但是 NumPy 数组和索引列表非常大。我非常感谢一个快速有效的解决方案(没有循环,最好是切片或其他可能)来替换数组值,因为我需要通过使用这样的索引列表以最小的延迟替换值来创建数千个数组。
解决方案
推荐阅读
- controls - VFD的ASCII控制
- android - 添加“com.google.android.material:material:1.0.0-beta01”后,我们在创建签名 APK 时遇到了问题
- android - 如何在kotlin中的图标上写字
- airflow - Apache Airflow - 如何在使用 TriggerDagRunOperator 触发的流中检索运算符外部的 dag_run 数据
- angular - 具有多个模块(如 JHipster)的项目中的嵌套角度组件
- java - Java 接口中的默认方法:如何使用 JavaDoc?
- apache-spark - Spark 结构化流式处理 Kafka 微批量计数
- c - 寻找 C w/openssl 等效于 java bouncycastle SHA256withRSA 签名
- python - Python icalendar 无法识别密钥
- azure - 无法使用 Azure Fluent 获取存储帐户密钥