如何访问盒装数组的第n列? [英] How do I access the n-th column of a boxed array?
本文介绍了如何访问盒装数组的第n列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定我有一个形状为 4 3
v =. 4 3$'x1'; 'y1'; 'z1'; 'x2'; 'y2'; 'z2'; 'x3'; 'y3'; 'z3'
v
NB. +--+--+--+
NB. |x1|y1|z1|
NB. +--+--+--+
NB. |x2|y2|z2|
NB. +--+--+--+
NB. |x3|y3|z3|
NB. +--+--+--+
NB. |x1|y1|z1|
NB. +--+--+--+
选择
我可以通过 1 {:: v
1{::v
NB. Get the second row
NB. +--+--+--+
NB. |x2|y2|z2|
NB. +--+--+--+
投影
但是如何访问第二列?
Projection
But how do I access the second column?
NB. Get the second column
NB. +--+
NB. |y1|
NB. +--+
NB. |y2|
NB. +--+
NB. |y3|
NB. +--+
NB. |y1|
NB. +--+
推荐答案
您还可以指定等级 {和
:
1 {"1 v
NB. +--+--+--+--+
NB. |y1|y2|y3|y4|
NB. +--+--+--+--+
这将为您提供第二列,减去等级,因此只是形状为 4
的数组。要使其形状为 4 1
,请使用Ravel Items ,。
:
This will give you the second column, minus a rank, so just an array of shape 4
. To get it to shape 4 1
, use Ravel Items ,.
:
,.1 {"1 v
NB. +--+
NB. |y1|
NB. +--+
NB. |y2|
NB. +--+
NB. |y3|
NB. +--+
NB. |y1|
NB. +--+
此外,无论是否将矩阵装箱,所有这些逻辑都适用。
Also, all this logic applies whether the matrix is boxed or not.
这篇关于如何访问盒装数组的第n列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文