Function Repository Resource:

FlatTable

Source Notebook

A flattened version of Table

Contributed by: Wolfram Staff

ResourceFunction["FlatTable"][expr,n]

generates a list of n copies of expr.

ResourceFunction["FlatTable"][expr,n,m]

gives a list of n×m copies of expr.

ResourceFunction["FlatTable"][expr,{i,},{j,},]

gives a list of the values of expr in which i is incremented last.

ResourceFunction["FlatTable"][args]

gives a flattened version of Table[args].

Details

In ResourceFunction["FlatTable"][args], args are the same as in Table[args].
ResourceFunction["FlatTable"][args], is effectively equivalent to Flatten[Table[args],Length[{args}]-2].
ResourceFunction["FlatTable"] has the attribute HoldAll, similar to Table.

Examples

Basic Examples (3) 

A table of the first 5 squares:

In[1]:=
ResourceFunction["FlatTable"][i^2, {i, 5}]
Out[1]=

A flattened version of a 4⨯3 matrix:

In[2]:=
ResourceFunction["FlatTable"][10 i + j, {i, 4}, {j, 3}]
Out[2]=

A flattened version of a triangular array:

In[3]:=
ResourceFunction["FlatTable"][10 i + j, {i, 5}, {j, i}]
Out[3]=

Compare:

In[4]:=
Table[10 i + j, {i, 5}, {j, i}] // TableForm
Out[4]=

Properties and Relations (3) 

For non-list expr, FlatTable[expr,…] is equivalent to Flatten[Table[expr,…]]:

In[5]:=
ResourceFunction["FlatTable"][
 f[i, j, k], {i, 100, 101}, {j, 20, 22}, {k, 4}]
Out[5]=
In[6]:=
% === Flatten[Table[f[i, j, k], {i, 100, 101}, {j, 20, 22}, {k, 4}]]
Out[6]=

FlatTable preserves lists in expr:

In[7]:=
ResourceFunction["FlatTable"][{10 i + j}, {i, 2}, {j, 3}]
Out[7]=

Compare to Flatten[Table[expr,…]]:

In[8]:=
Flatten[Table[{10 i + j}, {i, 2}, {j, 3}]]
Out[8]=

For two-dimensional tables, FlatTable[expr,…] is equivalent to Catenate[Table[expr,…]]:

In[9]:=
ResourceFunction["FlatTable"][{10 i + j}, {i, 2}, {j, i}]
Out[9]=
In[10]:=
% === Catenate[Table[{10 i + j}, {i, 2}, {j, i}]]
Out[10]=

Version History

  • 1.0.0 – 18 January 2021

License Information