def foo(i):
#transform int to binary
return binary
full_sample_arr = np.arange(2**24).reshape(-1,1)
int_to_binary_ufunc1 = np.frompyfunc(int_to_binary_24,1,1)
y2 = int_to_binary_ufunc1(full_sample_arr)
#经np.frompyfunc之后,将单元素自变量i经复杂运算foo后返回j
#对于庞大的数组计算,该方式比单元素迭代速度快的多的多
原文:https://www.cnblogs.com/alilliam/p/11308882.html