I want to make an $n\times n$ matrix M[n_] with $(i,j)$-th entry given by a function $f(i,j)$. However $i$ and $j$ don't come from $\left\{1,2,...,n\right\},$ they come from another ordered set $\Phi$ of size $n$. It's difficult to explicitly write down a bijection from $\left\{1,2,\dots,n\right\}$ to $\Phi$, so is there any way to just have the entries of $M$ be indexed by $\Phi$ (and in a specified order)?

(If it makes a difference, $n={k\choose 2}$ and $\Phi$ is the set of pairs $(r,s)$ with $1\leq r<s\leq k$. A bijection from $\Phi$ to $\left\{1,2,\dots,n\right\}$ is given by $(r,s)\mapsto r+{s-1\choose 2}$, but I cant find a nice way to write down the inverse.)

  • 4
    $\begingroup$ Could use Table[]: Φ = Subsets[Range[k], {2}]; Table[f[r, s], {r, Φ}, {s, Φ}] $\endgroup$ – J. M.'s technical difficulties Apr 2 '18 at 0:58
  • $\begingroup$ Thanks! (I dont use mathematica much if you can't tell...) $\endgroup$ – anon Apr 2 '18 at 2:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.