TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

How would you explain a tensor to a computer scientist?

8 点作者 azeemba9 个月前

1 comment

librasteve9 个月前
Since the article is quite diverse in its coverage, I have tried to extract the answers that work for me:<p>—-<p>A computer scientist should have no trouble to understand what multi-dimensional arrays are: v[i] vector, m[i,j] matrix, t[i,j,k] 3rd order tensor, and so on.<p>—-<p>From a CS perspective I would explain that tensors are, indeed, multi-dimensional arrays plus a number of basic operations on them that have turned out to be very useful in a lot of applications. For example, most of the operations in a popular library as numpy can be constructed from the following building blocks (not an exhaustive list):<p><pre><code> - Reordering of indices. - Applying a binary operator ⋆ to arrays with equal dimensions: (A⋆B)[I]=A[I]⋆B[I]. - Free tensor product of arrays: (A⊗B)[I,J]=A[I]⋅B[J]. - Introducing additional indices of any dimension: A′[I,J]=A[I]. - Contraction of two indices with equal dimension: A′[I]=∑kA[k,k,I]. </code></pre> Of course, there are also some not so trivial operations on certain tensors, such as inversion or QR factorization, and so on. However, understanding how a library supports the operations above will make it much easier to understand. The often countless functions that a library offers are mostly just clever and optimized combinations of these basic operations. For example, a matrix multiplication is a combination of a free tensor product and a contraction. The trace of a square matrix is a contraction. And so on.<p>—-<p>The answer is in using multi-array, but in a specific way. By using the array dimensions to represent contravariant and covariant indices, you can effectively distinguish between different types of tensors and their corresponding transformations.<p>Start with<p>int[1,3]: This represents a 1-rank tensor with contravariant indices (row indices)<p>int[3,1]: This represents a 1-rank tensor with covariant indices (column indices)<p>Then up<p>int[1,3][1,3]: This represents a 2-rank tensor with contravariant indices (row indices) for both dimensions.<p>int[1,3][3,1]: This represents a 2-rank tensor with contravariant indices (row indices) for the first dimension and covariant indices (column indices) for the second dimension.<p>int[3,1][1,3]: This represents a 2-rank tensor with covariant indices (column indices) for the first dimension and contravariant indices (row indices) for the second dimension.<p>int[3,1][3,1]: This represents a 2-rank tensor with covariant indices (column indices) for both dimensions.<p>And so on for higher ranks&#x2F;dimensions. (All examples use size 3, but you can have any size, and of course any type not just integers.)<p>This notation aligns with the mathematical representation of tensors and allows for easy interpretation of the tensor&#x27;s structure and transformation properties.