python – 多维数组中列的平方和的平方根
发布时间:2020-12-20 12:05:42 所属栏目:Python 来源:网络整理
导读:我正在使用numpy的多维列表 我有一份清单. l = [[0 2 8] [0 2 7] [0 2 5] [2 4 5] [ 8 4 7]] 我需要找到平方列之和的平方根. 0 2 80 2 70 2 52 4 58 4 7 输出为, l = [sqrt((square(0) + square(0) + square(0) + square(2) + square(8)) sqrt((square(2) +
我正在使用numpy的多维列表
我有一份清单. l = [[0 2 8] [0 2 7] [0 2 5] [2 4 5] [ 8 4 7]] 我需要找到平方列之和的平方根. 0 2 8 0 2 7 0 2 5 2 4 5 8 4 7 输出为, l = [sqrt((square(0) + square(0) + square(0) + square(2) + square(8)) sqrt((square(2) + square(2) + square(2) + square(4) + square(4)) sqrt((square(8) + square(7) + square(5)) + square(5) + square(7))] 解决方法>>> import numpy as np >>> a = np.array([[0,2,8],[0,7],5],[2,4,[ 8,7]]) >>> np.sqrt(np.sum(np.square(a),axis=0)) array([ 8.24621125,6.63324958,14.56021978]) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |