Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在函数中使用类型化列表_Python_Numpy_Numba - Fatal编程技术网

Python 在函数中使用类型化列表

Python 在函数中使用类型化列表,python,numpy,numba,Python,Numpy,Numba,我正在尝试用numba加速一些简单的函数。 下面的第一个函数起作用,但给出了一个弃用警告,表示列表的反射正在被删除,并使用numba.typed.list from numba import jit from numba.typed import List as NBList import numpy as np from typing import List @jit(nopython=True) def water_added_to_pp_refl(water_added: List[i

我正在尝试用numba加速一些简单的函数。 下面的第一个函数起作用,但给出了一个弃用警告,表示列表的反射正在被删除,并使用numba.typed.list

from numba import jit
from numba.typed import List as NBList
import numpy as np
from typing import List


@jit(nopython=True)
def water_added_to_pp_refl(water_added: List[int], vessel_volume: int = 1000
                           ) -> np.ndarray:
    """convert list of amounts of water in mg to array of partial pressures for a given volume"""
    wadd_array = np.array(water_added)
    print(wadd_array)
    return np.divide(wadd_array, vessel_volume)

output_reflected = water_added_to_pp_refl([10, 25, 50, 75, 100, 150, 200, 250])  # this works, but warning
当我将列表转换为numba.list时,它无法创建数组:

@jit(nopython=True)
def water_added_to_pp_NBList(water_added: List[int], vessel_volume: int = 1000
                             ) -> np.ndarray:
    """convert list of amounts of water in mg to array of partial pressures for a given volume"""
    water_list = NBList()
    [water_list.append(x) for x in water_added]
    wadd_array = np.array(water_list)
    print(wadd_array)
    return np.divide(wadd_array, vessel_volume)

output_NBListed = water_added_to_pp_NBList([10, 25, 50, 75, 100, 150, 200, 250]) # fails to create array
有误:

我尝试将数组的数据类型设置为np.int64,但没有成功

如何将numba.typed.list与numpy数组一起使用?可能吗

There are 2 candidate implementations:
   - Of which 2 did not match due to:
   Overload in function 'array': File: numba\core\typing\npydecl.py: Line 482.
     With argument(s): '(ListType[int64])':
    Rejected as the implementation raised a specific error:
      NotImplementedError: ListType[int64] cannot be represented as a Numpy dtype