Python - 在数组列表中查找比率

cc6*_*g11 -3 python arrays nested list

我有一个数据结构

my_list = [ [a, b], [c,d], [e,f], [g,h], [i, j], [k, l] ....]
Run Code Online (Sandbox Code Playgroud)

字母是浮点数.

我需要找到c,e和a之间的比率>>>> c/a ... e/a然后找到d,f和b之间的比率>>>> d/b,f/b并继续列表中的所有元素12个元素.所以计算了8个比率.

是否有一个函数可以有效地执行此操作,因为我们在列表元素之间进行操作?无需先单独提取数组中的数据,然后进行数学计算.

Dor*_*Ron 5

ex_array = [[5.0, 2.5], [10.0, 5.0], [20.0, 13.0]]  # makes    ndarray, which makes division easier

for i in xrange(len(ex_array)):
    print "\n"  + str(ex_array[i][0]) + " ratios for x values:\n"
    for j in xrange(len(ex_array)):
        print str(ex_array[i][0] / ex_array[j][0]) + "\t|{} / {}".format(ex_array[i][0], ex_array[j][0])  # gives ratios for each nested 0 index values against the others

for i in xrange(len(ex_array)):
    print "\n"  + str(ex_array[i][1]) + " ratios for x values:\n"
    for j in xrange(len(ex_array)):
        print str(ex_array[i][1] / ex_array[j][1]) + "\t|{} / {}".format(ex_array[i][1], ex_array[j][1])   # gives ratios for each nested 1 index values against the others
Run Code Online (Sandbox Code Playgroud)

输出格式如下: 在此输入图像描述