tf.matmul

简介:
matmul(a, b, transpose_a=False, transpose_b=False, adjoint_a=False, adjoint_b=False, a_is_sparse=False, b_is_sparse=False, name=None)
    Multiplies matrix `a` by matrix `b`, producing `a` * `b`.
    
    The inputs must, following any transpositions, be tensors of rank >= 2
    where the inner 2 dimensions specify valid matrix multiplication arguments,
    and any further outer dimensions match.
    
    Both matrices must be of the same type. The supported types are:
    `float16`, `float32`, `float64`, `int32`, `complex64`, `complex128`.
    
    Either matrix can be transposed or adjointed (conjugated and transposed) on
    the fly by setting one of the corresponding flag to `True`. These are `False`
    by default.
    
    If one or both of the matrices contain a lot of zeros, a more efficient
    multiplication algorithm can be used by setting the corresponding
    `a_is_sparse` or `b_is_sparse` flag to `True`. These are `False` by default.
    This optimization is only available for plain matrices (rank-2 tensors) with
    datatypes `bfloat16` or `float32`.
    
    For example:
    
    ```python
    # 2-D tensor `a`
    # [[1, 2, 3],
    #  [4, 5, 6]]
    a = tf.constant([1, 2, 3, 4, 5, 6], shape=[2, 3])
    
    # 2-D tensor `b`
    # [[ 7,  8],
    #  [ 9, 10],
    #  [11, 12]]
    b = tf.constant([7, 8, 9, 10, 11, 12], shape=[3, 2])
    
    # `a` * `b`
    # [[ 58,  64],
    #  [139, 154]]
    c = tf.matmul(a, b)
    
    
    # 3-D tensor `a`
    # [[[ 1,  2,  3],
    #   [ 4,  5,  6]],
    #  [[ 7,  8,  9],
    #   [10, 11, 12]]]
    a = tf.constant(np.arange(1, 13, dtype=np.int32),
                    shape=[2, 2, 3])
    
    # 3-D tensor `b`
    # [[[13, 14],
    #   [15, 16],
    #   [17, 18]],
    #  [[19, 20],
    #   [21, 22],
    #   [23, 24]]]
    b = tf.constant(np.arange(13, 25, dtype=np.int32),
                    shape=[2, 3, 2])
    
    # `a` * `b`
    # [[[ 94, 100],
    #   [229, 244]],
    #  [[508, 532],
    #   [697, 730]]]
    c = tf.matmul(a, b)
    
    # Since python >= 3.5 the @ operator is supported (see PEP 465).
    # In TensorFlow, it simply calls the `tf.matmul()` function, so the
    # following lines are equivalent:
    d = a @ b @ [[10.], [11.]]
    d = tf.matmul(tf.matmul(a, b), [[10.], [11.]])
    ```
    
    Args:
      a: `Tensor` of type `float16`, `float32`, `float64`, `int32`, `complex64`,
        `complex128` and rank > 1.
      b: `Tensor` with same type and rank as `a`.
      transpose_a: If `True`, `a` is transposed before multiplication.
      transpose_b: If `True`, `b` is transposed before multiplication.
      adjoint_a: If `True`, `a` is conjugated and transposed before
        multiplication.
      adjoint_b: If `True`, `b` is conjugated and transposed before
        multiplication.
      a_is_sparse: If `True`, `a` is treated as a sparse matrix.
      b_is_sparse: If `True`, `b` is treated as a sparse matrix.
      name: Name for the operation (optional).
    
    Returns:
      A `Tensor` of the same type as `a` and `b` where each inner-most matrix is
      the product of the corresponding matrices in `a` and `b`, e.g. if all
      transpose or adjoint attributes are `False`:
    
      `output`[..., i, j] = sum_k (`a`[..., i, k] * `b`[..., k, j]),
      for all indices i, j.
    
      Note: This is matrix product, not element-wise product.
    
    
    Raises:
      ValueError: If transpose_a and adjoint_a, or transpose_b and adjoint_b
        are both set to True.
目录
相关文章
|
9月前
|
缓存 监控 API
使用API获取新加坡股票数据的完整指南
本文为开发者提供获取新加坡股票数据的完整API指南,涵盖股票列表、历史K线、STI指数等核心接口调用方法,附Python实战示例(含实时监控、量化回测、WebSocket订阅与缓存优化),助力金融科技应用高效开发。(239字)
|
11天前
|
弹性计算 程序员 测试技术
个人/企业/学生全覆盖:阿里云免费服务器申领条件与时长说明
阿里云为个人新用户、在校大学生和企业新用户提供免费ECS试用权益:个人可领300元额度(3个月),学生认证后享最长7个月2核2G服务器,企业享660元额度。附详细申领指南与避坑提示,助你零成本上云试错!
269 0
|
JavaScript 关系型数据库 PostgreSQL
Rachoon:基于 TypeScript 和 PostgreSQL 的自部署发票管理系统
Rachoon 是开源发票管理系统,支持发票生成、客户管理和付款跟踪。基于 TypeScript 和 PostgreSQL 开发,通过 Docker 快速部署。数据存储在自己服务器,适合自由职业者和小团队使用,无订阅费用。
580 19
|
5月前
|
机器学习/深度学习 JSON 安全
从零搓一个语言模型,然后把它变成认知体的声带
这是一个“反着来”的硬核项目:不调包、不微调、不套壳,从张量运算手搓197万参数的轻量语言模型(62MB/73文件),专为认知体设计为“声带”——仅负责流畅表达,不替代意识与记忆。内置三层漏斗架构+34个JSON回路专家(MoE路由),OpenAI兼容接口,真正实现小模型与大模型的智能分工。(239字)
|
测试技术 持续交付 开发工具
吞噬混沌:CodeBuddy与流程利刃,斩破游戏开发的蛮荒时代(二)
本文参加CodeBuddy「首席试玩官」大赛,探讨游戏开发流程规范与智能工具赋能。文章涵盖质量保障体系(每日构建、代码审查、测试会议)、开发工具链、紧急情况处理(热修复与回滚机制)及代码风格指南。重点介绍CodeBuddy在各环节的作用:优化构建、智能评审、加速修复、保障风格一致等。作为贯穿生命周期的智能助手,CodeBuddy连接工具链、提升效率、沉淀经验,助力团队实现高质量开发目标。未来游戏开发需结合规范与技术,CodeBuddy将成为不可或缺的智能向导。
851 7
|
数据采集 数据可视化 数据挖掘
从信息捕获到多维研判的链路解析
本案例构建了一套基于爬虫与数据分析的热点监测系统,通过代理IP与Python工具实现新闻内容抓取,结合时间、来源与关键词分析,打造“信息雷达”,助力舆情研判与趋势预测。
484 7
从信息捕获到多维研判的链路解析
|
存储 运维 监控
云时代,好用的数据迁移方案推荐
本文将介绍数据库迁移的步骤以及市面上常见的迁移工具,推荐大家选择能够支持“业务零停机迁移”的工具产品。同时,平台工具(例NineData) 的自动化体验及配套设施(例:数据校验工具、迁移限流、监控告警等)一般较为完善,是比较推荐的选择。
1820 1
云时代,好用的数据迁移方案推荐
|
人工智能 自然语言处理
使用企业微信或公众号自动回复图片消息
AppFlow支持企业微信和公众号接收图片消息,并提供两种回复方式。方式一:直接回复图片消息,用户发送图片后立即收到回复,但无法继续追问。方式二:先保存图片,待用户发送文字后再一并处理并回复。配置步骤包括选择模板、配置鉴权信息、设置执行动作参数及发布连接流。详细操作可参考相关文档。
2169 1
使用企业微信或公众号自动回复图片消息
|
存储 人工智能 机器人
jetson nano开发使用的基础详细分享
jetson nano开发使用的基础详细分享
2444 1
jetson nano开发使用的基础详细分享
|
运维 安全 网络安全
.NET HttpWebRequest(请求被中止: 未能创建 SSL/TLS 安全通道)和(基础连接已经关闭: 发送时发生错误)问题查找解决
.NET HttpWebRequest(请求被中止: 未能创建 SSL/TLS 安全通道)和(基础连接已经关闭: 发送时发生错误)问题查找解决
1558 0
.NET HttpWebRequest(请求被中止: 未能创建 SSL/TLS 安全通道)和(基础连接已经关闭: 发送时发生错误)问题查找解决