我想做这样的事情
def foo(x,dtype=long):
return magic_function_changing_listtype_to_dtype(x)
Run Code Online (Sandbox Code Playgroud)
即一个完整的列表到一个完整的int列表
任何简单的方法来嵌套列表,即更改类型[['1'],['2']] - > int
我将向量类导入到cython使用时遇到问题
from libcpp.vector cimport vector
Run Code Online (Sandbox Code Playgroud)
当我添加这个并尝试编译我得到的pyx文件
python setup.py build_ext --inplace
running build_ext
skipping 'kmc_cy.c' Cython extension (up-to-date)
building 'kmc_cy' extension
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -fPIC -I/usr/include/python2.7 -c kmc_cy.c -o build/temp.linux-x86_64-2.7/kmc_cy.o
kmc_cy.c:254:18: fatal error: vector: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
Run Code Online (Sandbox Code Playgroud)
这是我的setup.py
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
import sys
sys.path.append("/usr/lib64/python2.7/site-packages/Cython/Includes/libcpp")
ext_modules = [Extension("kmc_cy", ["kmc_cy.pyx"])]
setup( …
Run Code Online (Sandbox Code Playgroud) 我在matlab中寻找像列表推导这样的东西但是我在纪录片中找不到这样的东西.
在python中它会是这样的
A=[i/50 for i in range(50)]
Run Code Online (Sandbox Code Playgroud) 我有Cython的以下内联函数
cpdef inline int c_rate2recs_2(int maxNN,int idx):
cdef int out=idx%maxNN
return out
Run Code Online (Sandbox Code Playgroud)
然而,这转化为
/*
* return out
*
* cpdef inline int c_rate2recs_2(int maxNN,int idx): # <<<<<<<<<<<<<<
* cdef int out=idx%maxNN
* return out
*/
static PyObject *__pyx_pw_6kmc_cy_5c_rate2recs_2(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static CYTHON_INLINE int __pyx_f_6kmc_cy_c_rate2recs_2(int __pyx_v_maxNN, int __pyx_v_idx, CYTHON_UNUSED int __pyx_skip_dispatch) {
int __pyx_v_out;
int __pyx_r;
__Pyx_TraceDeclarations
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("c_rate2recs_2", 0);
__Pyx_TraceCall("c_rate2recs_2", __pyx_f[0], 984);
/*
* return out
*
* cpdef inline int c_rate2recs_2(int maxNN,int idx): # <<<<<<<<<<<<<< …
Run Code Online (Sandbox Code Playgroud) 我希望加快以下代码的速度:
NNlist=[np.unique(i) for i in NNlist]
Run Code Online (Sandbox Code Playgroud)
其中 NNlist 是具有重复条目的 np.arrays 列表。
谢谢 :)
以下MATLAB代码不起作用.我想这事做的是,在功能转换,MATLAB试图等于对象A
和B
而不仅仅是设置值相同.任何解决方法?
classdef foo
%FOO Summary of this class goes here
% Detailed explanation goes here
properties
A=5
B=0
end
methods
function changer(obj)
obj.B=obj.A
end
end
end
Run Code Online (Sandbox Code Playgroud) python ×3
cython ×2
matlab ×2
arrays ×1
import ×1
inline ×1
list ×1
matlab-class ×1
numpy ×1
optimization ×1
performance ×1
vector ×1