About Tensor Shape Calculator
This tensor shape calculator reads a tensor from nested brackets, or from a flat list plus a shape, and tells you its rank, shape and element count. It is free, needs no sign-up and runs in your browser, so nothing you enter is uploaded.
Nested brackets give you the shape directly: [[1, 2, 3], [4, 5, 6]] is shape [2, 3]. With a flat list, the product of the shape you type must equal the number of values, so 2, 3 needs six values. The rank is the number of axes, which is the length of the shape list.
Below the input, type a target shape to see whether a reshape is possible and what it produces. One entry can be -1, and the page fills it in. If the sizes do not divide, the message says so, for example "6 values cannot fill a shape with a fixed size of 4". You can also transpose: with no axes order the axes are reversed, which is the matrix transpose for rank 2, and with an order such as 1, 0, 2 you choose exactly how they are permuted.
How to use Tensor Shape Calculator
- Pick a mode: Shape and reshape, Tensor product, Kronecker product, or Einsum.
- Enter tensor A as nested brackets like [[1, 2, 3], [4, 5, 6]], or as a flat list of numbers with a shape such as 2, 3 in the shape box. One shape entry may be -1.
- For the product and einsum modes, enter tensor B the same way.
- In Shape mode, type a target shape to reshape to (for example 3, -1) and optionally an axes order for transpose (for example 1, 0).
- In Einsum mode, write the expression, such as ij,jk->ik, or pick an example chip: matrix product, trace, diagonal, transpose or a three-matrix chain. One box appears for each operand, labelled with its axes.
- Read the rank, shape and element count above each result, and the values below as nested brackets.
Features
- Shape inference from nested brackets, or a flat list plus a shape.
- Reshape with one -1 dimension worked out automatically.
- Transpose with reversed axes by default, or a custom axes order for any rank.
- Tensor (outer) product whose shape is the shape of A followed by the shape of B.
- Kronecker product with NumPy-style padding, so a vector and a matrix can be combined.
- Einsum with one, two or three operands: the trace (ii->), the diagonal (ii->i), the transpose (ij->ji), the matrix product, a three-matrix chain (ij,jk,kl->il), batch products and more, with an implicit output when you leave off the arrow.
- Each tensor box is labelled with the axes the expression gives it, and the expression is shown as a KaTeX formula.
- Shapes and small results are typeset with KaTeX, for example the shape as R with a superscript of 2 by 3 and a matrix as a bracketed array.
- A size guard: an einsum over 10 million multiply-adds is refused with the exact count, and one over 100,000 runs in a Web Worker so the page stays responsive.
- Readable errors for ragged lists, non-numbers, mismatched sizes and bad axes.
- Rank, shape and element count shown for every result, and values printed as nested brackets rounded to nine decimals.
Worked examples
1, 2, 3, 4, 5, 6 with shape 2, 3 gives Rank 2, shape [2, 3], 6 elements. Reshape to 3, -1: [[1, 2], [3, 4], [5, 6]]. Transpose: [[1, 4], [2, 5], [3, 6]].
24 values 0 to 23 with shape 2, 3, 4 gives Rank 3, 24 elements. Reversed axes give shape [4, 3, 2]. The order 1, 0, 2 gives [3, 2, 4]. Reshape to 4, -1 gives [4, 6].
1, 2, 3, 4, 5, 6 reshaped to 4, -1 gives Error: 6 values cannot fill a shape with a fixed size of 4.
Privacy: how it works
- All arithmetic is done by TypeScript code in your browser tab. There is no network request when you calculate, no library is downloaded to do it, and nothing is stored.
Tips
- Use -1 in a reshape to let the calculator fill in one dimension. A 24-element tensor reshaped to 4, -1 becomes shape [4, 6].
- If a reshape fails, multiply your target dimensions and compare with the element count shown for tensor A.
- To check an einsum string, try tiny tensors with distinct values, then compare the rank and shape before the values.
- A custom transpose order lists the old axes in their new positions. For shape [2, 3, 4], the order 1, 0, 2 gives shape [3, 2, 4].
Frequently asked questions
Is it really free?
Yes. There is no price, no trial and no credit card. Ulkaa Tool does the work with your own device, so there is no server bill to pass on to you.
Do I need an account?
No. There is no sign-up and no login. Open the page and use it. An Ulkaa account is not needed for anything on this tool.
Does it run in my browser?
Yes. Your values are processed by code running in your browser tab, on your own device.
Is my data uploaded?
No. Your values are never sent to Ulkaa or to anyone else. You can check this yourself by watching the Network tab in your browser developer tools while you use the tool.
What is the shape of a tensor?
It is the list of its axis sizes. A matrix with 2 rows and 3 columns has shape [2, 3] and rank 2.
What does -1 mean in a reshape?
It asks the calculator to work out that dimension from the element count. For 24 elements, reshaping to 4, -1 gives 4 by 6.
Why do I get a reshape error?
A reshape has to keep the number of elements. If the product of your target dimensions does not equal the element count, or the count does not divide by the fixed dimensions when you use -1, the reshape is impossible.
More Tensor Calculator pages
- Tensor CalculatorCheck shapes, reshape and transpose, and compute tensor products, Kronecker products and einsum contractions.
- Tensor Product CalculatorThe tensor product of two tensors, with the result shape worked out.
- Einsum CalculatorEvaluate einsum expressions on one to three tensors and check your own.
- Kronecker Product CalculatorThe Kronecker product of two matrices, with block layout.
- Tensor Contraction CalculatorContract two tensors by summing over shared indices.