I have a large numpy array with the following structure:
array([['A', 0.0, 0.0],
['B2', 1.0, 0.0],
['B4', 2.0, 3.0],
['AX1', 3.0, 1.0],
['C2', 0.0, 2.0],
['D3', 2.0, 1.0],
['X4', 3.0, 8.0],
['BN', 2.0, 9.0],
['VF', 12.0, 25.0],
['L', 1.0, 3.0],
...,
['s', 2.0, 27.0],
['P', 0.0, 0.0]], dtype=object)
I'm using cython to try and speed up the processing as much as possible. The argument dataset in the code below is the above array.
%%cython
cpdef permut1(dataset):
cdef int i
cdef int j
cdef str x
cdef str v
xlist = []
for i, x in enumerate(dataset[:,0]):
for j, v in enumerate(dataset[:,0]):
xlist.append((x,v,dataset[i][1], dataset[j][2]))
return xlist
However, when running the above code with and without cython I get the following times:
without cython: 0:00:00.945872
with cython: 0:00:00.561925
Any ideas how I can use cython to speed this up even more?
thanks
cdef str xandvis probably making it (slightly) worse. You don't use the type information at all so all you're adding is a pointless type check. That may be true foriandjtoo; I'm not sure.dataset[i][1]->dataset[i,1](it may be maginally quicker since it's one operation).cythonspeed improvements when using arrays, or code that can be readily translated intoc. Lists and arrays that have to reference other Python objects require a lot of Python code,even incython. There is a way of getting an annotatedhtmldisplay of your cython code. Bright yellow in that display indicates Python heavy lines.