In Sidef, we have the Array.wise_op() method, which takes two arbitrary nested arrays and an operator, folding each element (entrywise) with the provided operator, which is also available as a ~Wop b:
say ([1,2,[3,[4]]] ~W+ [42,43,[44,[45]]]) #=> [43, 45, [47, [49]]]
Alternatively:
say wise_op([1,2,[3,[4]]],'+', [42,43,[44,[45]]]) #=> [43, 45, [47, [49]]]
Scalar operations:
A`scalar_add`42# scalar addition (aliased as `sadd`)A`scalar_sub`42# scalar subtraction (aliased as `ssub`)A`scalar_mul`42# scalar multiplication (aliased as `smul`)A`scalar_div`42# scalar division (aliased as `sdiv`)
This methods are provided by Array.scalar_op(), which, just like Array.wise_op(), also supports arbitrary nested arrays: