pythonJax小记(三):python: 使用Jax已知若干坐标,提取二维矩阵中对应坐标的值(持续更新,评论区可以补充)

python: 使用Jax已知若干坐标,提取二维矩阵中对应坐标的值


前言

自用,刚开始接触可能顺序会比较乱。

直接上代码

python 复制代码
import jax.numpy as jnp
from jax import jit
 
@jit
def _extractValues(matrix, positions):         
    values = matrix[positions[:, 0], positions[:, 1]]     
    return values
    
matrix = jnp.array([[5,2,4,2,4,1,3,9,4],
					[3,4,0,2,8,8,0,9,5],
					[6,4,0,7,3,0,0,2,7],
					[2,7,1,6,9,1,6,2,4]])
positions = jnp.array([[0, 0],[1, 0],[2, 0],[2, 1],[3, 0],[3, 1],[3, 2],[0, 3],[0, 4],[0, 5],[1, 3],[1, 4],[1, 5],[2, 4],[2, 5],[2, 6],[3, 5],[3, 6]])

extracted_values = extract_values(matrix, positions)
print("Extracted Values: ",extracted_values )

输出:

bash 复制代码
Extracted Values: [ 4  2  4  3  1  4  0  0  2 -1  0  4  2  1 -2 -2 -1  2]
相关推荐
咖啡续命又一天18 分钟前
python 自动化采集 ChromeDriver 安装
开发语言·python·自动化
huohaiyu1 小时前
synchronized (Java)
java·开发语言·安全·synchronized
_OP_CHEN1 小时前
C++基础:(九)string类的使用与模拟实现
开发语言·c++·stl·string·string类·c++容器·stl模拟实现
蓝天智能1 小时前
QT MVC中View的特点及使用注意事项
开发语言·qt·mvc
松果集1 小时前
【1】数据类型2
python
且慢.5891 小时前
命令行的学习使用技巧
python
木觞清1 小时前
喜马拉雅音频链接逆向实战
开发语言·前端·javascript
海琴烟Sunshine2 小时前
leetcode 66.加一 python
python·算法·leetcode
wuxuanok2 小时前
苍穹外卖 —— 公共字段填充
java·开发语言·spring boot·spring·mybatis
偷光2 小时前
浏览器中的隐藏IDE: Console (控制台) 面板
开发语言·前端·ide·php