, , . , , , for. , 3 .
, :
import numpy as np
import time
def calc(no_nodes):
output = np.random.rand(no_nodes, 7e5) #some random data, 7e5 samples here
attenuate= np.random.rand(no_nodes,no_nodes) #some random data
start_time = time.time()
output_per_node = np.zeros((no_nodes,no_nodes,7e5))
output_per_node += output[None, :, :]
data = attenuate[:,:,None] * output_per_node
waveforms = np.sum(data, axis=1)
end_time = time.time()
print end_time - start_time
return waveforms
:
def calc1(no_nodes):
output = np.random.rand(no_nodes, 7e5)
attenuation = np.random.rand(no_nodes,no_nodes)
waveforms = np.zeros((no_nodes, 7e5))
start_time = time.time()
for i in range(no_nodes):
for j in range(no_nodes):
waveforms[i] += output[j] * attenuation[i,j]
print time.time() - start_time
return waveforms
? , Numpy , . , , - . cython, ( ) , , . , ?
: no_nodes = 10
, , ipython , , ipynb, html :
.