how to calculate the non linearity of each element of s box? I want to learn how to calculate the elementwise noninearity of an sbox. I know how to calculate the ANF, and how to create the s box. Now I wanna learn how to calculate the nonlinearity of s box elements "belement.before n after shuffling elements."
The answer to How does one practically calculate the non-linearity of a multi-output boolean function like the AES s-box? describes explicitly how to do this both for single output bits and the whole output vector of the sbox.

If you have the ANF of an sbox output bit, you can obtain its hadamard transform from there by using the mobius transform. See my answer to the question
Generate ANF from SBox for information on the mobius transform.

The weight of the lowest weight nonzero hadamard coefficient is equal to the nonlinearity.