Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Geometric mean is nth root of product of n numbers.

If you replace any of those numbers with 0, it will all collapse to 0 - perhaps not what you want. But it's not hard to write such a program:

      geometric_mean1 =: (+/ % #) &. (^."1) @: (0&>.)
      geometric_mean1 2 4 8
   4
      geometric_mean1 _2 4 8
   0
If you want to replace negative numbers with their positive counterparts, you may first replace a number with its absolute value:

      geometric_mean2 =: (+/ % #) &. (^."1) @: (>. -)
      geometric_mean2 _2 4 8
   4
      geometric_mean2 2 4 8
   4
Original geometric_mean probably meant to be

      geometric_mean =: (+/ % #) &. (^."1)
- note the copula (assignment symbol) and rank of first verb (^.) .


Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: