0

I have a multidimensional array

example =[[[1,1,2,2],[1,1,2,2]],[[1,1,3,3],[1,1,4,4]]]

for a simple call for an index a function used gives decent output

def calculate_sum(arr1,arr2):
    s = arr1[0]+arr2[0]+arr1[1]+arr2[3]
    return s

s = calculate_sum(example[1][0],example[1][1])
s

I can easily use for loop to iterate over example but want to know how to modify the function to vectorize over the array " example " to speed up the code

I have refered to similar threads but none deal with multidimensional arrays mapping properly

Most efficient way to map function over numpy array

Leothorn
  • 1,345
  • 1
  • 23
  • 45
  • You mention you want to **speed up the code** by using numpy.vectorize. But vecotrize function is not meant to be used for performance, but for convenience. Here's a extract from the documentation "The vectorize function is provided primarily for convenience, not for performance. The implementation is essentially a for loop." – Chayemor Oct 04 '19 at 08:40
  • Is there no method of vectorizing that has better speed than for loop ? I didnt know this was the case – Leothorn Oct 04 '19 at 08:45

0 Answers0