Is it possible to do the following with lambda? (I just need something which is able to do this really fast)
Asking for lambda because of this answer: https://stackoverflow.com/a/35216364/3776738
import numpy as np
def one_to_more(i):
//do some calculations etc...
return [i*3,i*9]
x = np.array([1, 2, 3])
f = lambda x: one_to_more(x)
more = f(x)
print(more)
---> [3,9,6,18,9,27]
EDIT: IT MUST NOT BE LAMBDA. I'm just looking for the fastest method to extend a large list or numpy array this way. This way means that it will have twice (the example code above or even longer length)
CLEANED:
this is the actual function used:
MAX_NUM=100000
def num_to_arr (num):
num = int(num)
if (num < 0 or num >= MAX_NUM):
num = 0
num3 = (num // 1600)
num2 = ((num - num3 * 1600) // 40)
num1 = int((num - num3 * 1600 - num2 * 40))
arr = [num1 / 40, num2 / 40, num3 / 40]
return arr
used like this:
result=list(map(num_to_arr,large_array))
The large array consist of about 10k integers and the execution time is about 17ms which is much too high. (CPU IS AMD RYZEN 7950X)