python中大于0的元素全部转化为1,小于0的元素全部转化为0的代码
作者:野牛程序员:2023-12-05 16:05:09python阅读 2713
python中大于0的元素全部转化为1,小于0的元素全部转化为0的代码
def transform_elements_to_binary(array): return [1 if element > 0 else 0 for element in array] # 示例用法 input_array = [2, -3, 5, -1, 0, 4] result = transform_elements_to_binary(input_array) print(result)
野牛程序员教少儿编程与信息学奥赛-微信|电话:15892516892

- 上一篇:DevC++单步调试的设置方法
- 下一篇:Python中大于0.5的数字转化为1