返回介绍

Generalized ufucns

发布于 2025-02-25 23:43:39 字数 1096 浏览 0 评论 0 收藏 0

A universal function performs vectorized looping over scalars. A generalized ufucn performs looping over vectors or arrays. Currently, numpy only ships with a single generalized ufunc. However, they play an important role for JIT compilation with numba , a topic we will cover in future lectures.

from numpy.core.umath_tests import matrix_multiply

print matrix_multiply.signature
(m,n),(n,p)->(m,p)
us = np.random.random((5, 2, 3)) # 5 2x3 matrics
vs = np.random.random((5, 3, 4)) # 5 3x4 matrices
# perform matrix multiplication for each of the 5 sets of matrices
ws = matrix_multiply(us, vs)
print ws.shape
print ws
(5, 2, 4)
[[[ 1.6525  0.7642  1.8964  0.831 ]
  [ 1.1368  0.5137  1.0785  0.7104]]

 [[ 1.0613  1.1923  1.2143  1.0832]
  [ 1.0266  0.8275  0.8543  0.6412]]

 [[ 0.8015  0.8953  0.358   0.4282]
  [ 0.3202  0.3222  0.2113  0.1709]]

 [[ 0.7747  1.0522  1.1458  0.892 ]
  [ 0.8178  1.1741  0.9486  1.0363]]

 [[ 1.5257  0.7962  1.3355  0.707 ]
  [ 1.3522  0.6577  0.9845  0.6013]]]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文