TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

How would you explain a tensor to a computer scientist?

8 pointsby azeemba9 months ago

1 comment

librasteve9 months ago
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.