本文整理汇总了Python中pypy.module.micronumpy.base.W_NDimArray.from_scalar方法的典型用法代码示例。如果您正苦于以下问题:Python W_NDimArray.from_scalar方法的具体用法?Python W_NDimArray.from_scalar怎么用?Python W_NDimArray.from_scalar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pypy.module.micronumpy.base.W_NDimArray
的用法示例。
在下文中一共展示了W_NDimArray.from_scalar方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: can_cast
# 需要导入模块: from pypy.module.micronumpy.base import W_NDimArray [as 别名]
# 或者: from pypy.module.micronumpy.base.W_NDimArray import from_scalar [as 别名]
def can_cast(space, w_from, w_totype, casting='safe'):
try:
target = as_dtype(space, w_totype, allow_None=False)
except TypeError:
raise oefmt(space.w_TypeError,
"did not understand one of the types; 'None' not accepted")
if isinstance(w_from, W_NDimArray):
return space.wrap(can_cast_array(space, w_from, target, casting))
elif is_scalar_w(space, w_from):
w_scalar = as_scalar(space, w_from)
w_arr = W_NDimArray.from_scalar(space, w_scalar)
return space.wrap(can_cast_array(space, w_arr, target, casting))
try:
origin = as_dtype(space, w_from, allow_None=False)
except TypeError:
raise oefmt(space.w_TypeError,
"did not understand one of the types; 'None' not accepted")
return space.wrap(can_cast_type(space, origin, target, casting))
示例2: result_type
# 需要导入模块: from pypy.module.micronumpy.base import W_NDimArray [as 别名]
# 或者: from pypy.module.micronumpy.base.W_NDimArray import from_scalar [as 别名]
def result_type(space, __args__):
args_w, kw_w = __args__.unpack()
if kw_w:
raise oefmt(space.w_TypeError,
"result_type() takes no keyword arguments")
if not args_w:
raise oefmt(space.w_ValueError,
"at least one array or dtype is required")
arrays_w = []
dtypes_w = []
for w_arg in args_w:
if isinstance(w_arg, W_NDimArray):
arrays_w.append(w_arg)
elif is_scalar_w(space, w_arg):
w_scalar = as_scalar(space, w_arg)
w_arr = W_NDimArray.from_scalar(space, w_scalar)
arrays_w.append(w_arr)
else:
dtype = as_dtype(space, w_arg)
dtypes_w.append(dtype)
return find_result_type(space, arrays_w, dtypes_w)