A fairly general method with expl3.
\documentclass{article}
\usepackage{xparse}
\usepackage{tikz}
\ExplSyntaxOn
\NewDocumentCommand{\setarray}{O{default}mm}
{% #1 is the name of the array
% #2 is the number of values
% #3 is the format of the values
\seq_clear_new:c { l_yngabl_array_#1_seq }
\int_step_inline:nnnn { 1 } { 1 } { #2 }
{
\seq_put_right:cx { l_yngabl_array_#1_seq } { \fp_eval:n { #3 } }
}
}
\NewExpandableDocumentCommand{\getvalue}{O{default}m}
{% #1 is the name of the array
% #2 is the index of the item to retrieve
\seq_item:cn { l_yngabl_array_#1_seq } { #2 }
}
\NewExpandableDocumentCommand{\mean}{O{2}m}
{% #1 is the optional number of decimal digits
% #2 is the name of the array (empty for default)
\fp_eval:n
{
round(
(\seq_use:cn { \__yngabl_array:n { #2 } } { + })/
\seq_count:c { \__yngabl_array:n { #2 } }
,#1)
}
}
\cs_new:Nn \__yngabl_array:n
{
l_yngabl_array_ \tl_if_blank:nTF { #1 } { default } { #1 } _seq
}
\ExplSyntaxOff
\begin{document}
\begin{tikzpicture}
\setarray{8}{randint(10)}
\node [] at (0,1) {\textbf{Values}};
\foreach \n in {1,...,8}{
\node [] at (1+\n,1) {$\getvalue{\n}$};
}
\node [] at (0,0) {\textbf{Mean}};
\node [] at (2,0) {$\mean{}$};
\end{tikzpicture}
\bigskip
\begin{tikzpicture}
\setarray{8}{round(rand(),3)}
\node [] at (0,1) {\textbf{Values}};
\foreach \n in {1,...,8}{
\node [] at (1+\n,1) {$\getvalue{\n}$};
}
\node [] at (0,0) {\textbf{Mean}};
\node [] at (2,0) {$\mean[3]{}$};
\end{tikzpicture}
\bigskip
\begin{tikzpicture}
\setarray[powers]{8}{round(2^#1/42,2)}
\node [] at (0,1) {\textbf{Values}};
\foreach \n in {1,...,8}{
\node [] at (1+\n,1) {$\getvalue[powers]{\n}$};
}
\node [] at (0,0) {\textbf{Mean}};
\node [] at (2,0) {$\mean{powers}$};
\end{tikzpicture}
\end{document}
As you see, the second mandatory argument to \setarray receives the instruction for computing a value. In this argument, #1 refers to the current array index when the computation is performed.

\pgfmathprintnumber{\boxplotvalue{median}}syntax. – Jun 11 '18 at 19:12