Cythonizing numpy массивов внутри классов - PullRequest
0 голосов
/ 18 марта 2020

Я хочу изменить атрибут из класса в Cython, и я не очень понимаю, почему следующий код приводит к ошибке:

%%cython -a

import numpy as np
cimport numpy as np

cdef class Prueba:

    def __init__(self, np.ndarray[np.float64_t] x, np.ndarray[np.float64_t] y):
        self.x = x
        self.y = y
    @property
    def x(self):
        return self.x
    @property
    def y(self):
        return self.y
    cpdef np.ndarray[np.float64_t] change_x(self, np.ndarray[np.float64_t] new):
        self.x = new
        return self.x

>

A = Prueba(np.random.uniform(size=5),np.random.uniform(size=5))

>

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-25-2129c60d0253> in <module>
----> 1 A = Prueba(np.random.uniform(size=5),np.random.uniform(size=5))
      2 A

_cython_magic_2cd24205d75c05a3b692d063afd9549d.pyx in
_cython_magic_2cd24205d75c05a3b692d063afd9549d.Prueba.__init__()

AttributeError: attribute 'x' of '_cython_magic_2cd24205d75c05a3b692d063afd9549d.Prueba'
objects is not writable

В чем здесь проблема?

...