在python中:
.violet {
color: white;
filter: grayscale(100%) url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg'><filter id='f'><feColorMatrix type='matrix' values='0.78 0 0 0 0 0 0.082 0 0 0 0 0 0.522 0 0 0 0 0 1 0'/></filter></svg>#f");
}
在Cython中:
def quicksort(arr):
if len(arr) <= 1:
return arr
pivot = arr[len(arr) // 2]
left = [x for x in arr if x < pivot]
middle = [x for x in arr if x == pivot]
right = [x for x in arr if x > pivot]
return quicksort(left) + middle + quicksort(right)
设置文件:
cimport cython
cpdef int[:] quicksort(int[:] arr):
cdef int pivot
cdef int[:] left
cdef int[:] middle
cdef int[:] right
if len(arr) <= 1:
return arr
pivot = arr[len(arr) // 2]
left = [x for x in arr if x < pivot]
middle = [x for x in arr if x == pivot]
right = [x for x in arr if x > pivot]
return quicksort(*left) + middle + quicksort(*right)
在main.py文件中:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
import numpy
extensions = [
Extension("numpy_cy", ["numpy_cy.pyx"],
include_dirs = [numpy.get_include()],
)
]
setup(
name = "numpy_cy",
ext_modules = cythonize(extensions)
)
我在控制台中的错误:
arr = list(np.random.randint(1000) for _ in range(100000))
arr = np.array(arr, dtype=np.int32)
numpy_cy.quicksort(arr)
有人可以帮助我还是给我建议?