Skip to content

TypeError: array indices must be integers or slices, not int64 #495

@phatnguyen1999p

Description

@phatnguyen1999p

Chaquopy version

  • Chaquopy version 9.1.0

Devices or emulators where the issue happens

  • Android Smartphone - Vsmart Live - Android 10

Relevant parts of your code

//Java part

PyObject PRV = pyObject.callAttr("PRV_analyser", tempData.getIRstoArray(), tempData.getIRstoArray(), 25);
PRV.callAttr("signal_filter");
PRV.callAttr("signal_calculator");
PyObject SpO2 = PRV.callAttr("SpO2_calculator");

// Python part

import heartpy
import numpy

class PRV_analyser():
    /.../
     def SpO2_calculator(self):
         R = []
         size = len(self.working_data_IR['peaklist'])
         print(type(size))
 
         for x in range(size):
             IR_median = self.Signal_IR[self.working_data_IR['peaklist'][int(x)]] - \
                 [self.working_data_IR['ybeat'][int(x)]]
             RED_median = self.Signal_RED[self.working_data_RED['peaklist'][int(x)]] - \
                 [self.working_data_RED['ybeat'][int(x)]]
 
             # Calculating R ratio (AC_IR * DC_RED)/(DC_IR * AC_RED)
             R.append(float((self.working_data_IR['ybeat'][int(x)] * RED_median) /
                            (self.working_data_RED['ybeat'][int(x)] * IR_median)))
 
         R = numpy.array(R)
         SpO = 104 - 17*R
         SpO2 = numpy.sum(SpO)/len(SpO)
         return SpO2

Describe your issue

I got an issue about TypeError Exception of x value when I launch my python code from java. But when I calling this function from python script, the error doesn't happen. Here is my debug error:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.healthdevice, PID: 13761
    com.chaquo.python.PyException: TypeError: array indices must be integers or slices, not int64
        at <python>.java.chaquopy.JavaArray._invalid_key(array.pxi:170)
        at <python>.java.chaquopy.JavaArray.__getitem__(array.pxi:132)
        at <python>.PRV_analyser.SpO2_calculator(PRV_analyser.py:46)
        at <python>.chaquopy_java.call(chaquopy_java.pyx:380)
        at <python>.chaquopy_java.Java_com_chaquo_python_PyObject_callAttrThrowsNative(chaquopy_java.pyx:352)
        at com.chaquo.python.PyObject.callAttrThrowsNative(Native Method)
        at com.chaquo.python.PyObject.callAttrThrows(PyObject.java:232)
        at com.chaquo.python.PyObject.callAttr(PyObject.java:221)
        at com.example.healthdevice.MainActivity.lambda$onCreate$2$MainActivity(MainActivity.java:136)
        at com.example.healthdevice.-$$Lambda$MainActivity$CtWii84LN6gVm9CXafLLaSQv6Ik.onItemClick(Unknown Source:8)
        at android.widget.AdapterView.performItemClick(AdapterView.java:330)
        at android.widget.AbsListView.performItemClick(AbsListView.java:1213)
        at android.widget.AbsListView$PerformClick.run(AbsListView.java:3221)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7458)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions