如何使用INDEX()进行嵌套数组计算? [英] How to make nested array computations with INDEX()?

查看:463
本文介绍了如何使用INDEX()进行嵌套数组计算?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下,我有几个(即> 100)列的数字向量。向量大,长度相等(例如20k项)。这些向量不是相邻的,所以它们不会构成一个矩阵。



我想要的是使用向量获得一些逐行计算,例如

对于每一行,所有向量中的第一个非零值是什么?





对于每一行,所有向量中的最大值是多少?



这个简化的例子,应该得到所有向量的最大值,对于所有行,这将为3(实际上显示的值为1):





这将很容易,如果我可以复制向量作为矩阵,并获得跨越给定行的所有向量而不是列范围的行范围的列。但是由于数据的大小,这不是选项。我认为这与其他SO问题有关:可以将数组作为INDIRECT()的参数,所以INDIRECT()返回数组?

您可以使用CHOOSE将等大小的列合并成一个范围,例如对于您的3范围范例:



=选择({1,2,3},$ B $ 1:$ B $ 4,$ B $ 5: $ B $ 8,$ A $ 3:$ A $ 6)



然后直接在公式中使用,例如在G2中复制,以获取每一行的MAX为您的示例



= MAX(INDEX(CHOOSE({1,2,3}, $ B $ 1:$ B $ 4,$ B $ 5:$ B $ 8,$ A $ 3:$ A $ 6),F2,0))



或您可以将CHOOSE部分定义为命名范围[如果您有100个范围,尤其有用],例如命名为Matrix并使用



= MAX(INDEX(Matrix,F2,0))



您需要根据范围数量修改{1,2,3}部分,当您可以使用100个范围时使用快捷方式



=选择(TRANSPOSE(ROW(INDIRECT(1:100))),Range1,Range2 ..... Range100)



现在需要使用 CTRL + SHIFT + ENTER



要获得第一个非零值,您可以使用此版本



= INDEX(INDEX(Matrix,F2 ,0),MATCH(TRUE,INDEX(Matrix,F2,0)< 0,0))



CTRL + SHIFT + ENTER


Imagine I have several (i.e. > 100) column vectors of numbers. Vectors are large with equal length (e.g. 20k items). The vectors are not adjacent, so they don't make a matrix.

What I want, is to get some row-wise computation with the vectors, for instance

For each row what is the first non zero value among all vectors?

or

For each row what is the maximal value among all vectors?

See this simplified example, that should get the maximal value for all vectors, which would be 3 for all row (in reality the displayed value is 1):

It would be easy, if I could copy the vectors as a matrix and get the column of row ranges that spans all vectors for a given row, instead of the column ranges. But that is not the option due to the size of the data. I think it is related to other SO question: Is it possible to have array as an argument to INDIRECT(), so INDIRECT() returns array?.

解决方案

You can use CHOOSE to combine equal sized columns into a single range, e.g. for your 3 range example:

=CHOOSE({1,2,3},$B$1:$B$4,$B$5:$B$8,$A$3:$A$6)

Then use that directly in a formula, e.g. in G2 copied down to get the MAX in each row for your example

=MAX(INDEX(CHOOSE({1,2,3},$B$1:$B$4,$B$5:$B$8,$A$3:$A$6),F2,0))

or you can define the CHOOSE part as a named range [especially useful if you have 100 ranges], e.g. name that Matrix and use

=MAX(INDEX(Matrix,F2,0))

You need to modify the {1,2,3} part based on the number of ranges, to shortcut when you have 100 ranges you can use

=CHOOSE(TRANSPOSE(ROW(INDIRECT("1:100"))),Range1, Range2.....Range100)

Now needs to be confirmed with CTRL+SHIFT+ENTER

To get the first non-zero value you can use this version

=INDEX(INDEX(Matrix,F2,0),MATCH(TRUE,INDEX(Matrix,F2,0)<>0,0))

also confirmed with CTRL+SHIFT+ENTER

这篇关于如何使用INDEX()进行嵌套数组计算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆