gpt4 book ai didi

How to convert a state to an index with Julia code [closed](如何使用Julia代码将状态转换为索引[已关闭])

转载 作者:bug小助手 更新时间:2023-10-24 19:52:41 24 4
gpt4 key购买 nike




I'm going to make a matrix with Julia code, but I'm going to convert the state in rows and columns to index first, so please tell me how. For example, I'm trying to convert the state of a row called (0100000) to an index called 1, what code should I use?

我将使用Julia代码创建一个矩阵,但我将首先将行和列中的状态转换为索引,所以请告诉我如何转换。例如,我试图将名为(0100000)的行的状态转换为名为1的索引,我应该使用什么代码?


更多回答

This question is confusing and difficult to answer. It is not clear what you mean by 'state of a row', or what 0100000 means. Are those the values in the row? Please expand your question, and provide clear examples directly in the question (not just in comments).

这个问题令人困惑,也很难回答。目前还不清楚你所说的“一排状态”是什么意思,也不清楚0100000是什么意思。这些是该行中的值吗?请扩展您的问题,并在问题中直接提供明确的例子(而不仅仅是在评论中)。

优秀答案推荐

It's generally better to operate columnwise rather than rowwise in Julia, as it is a column-major language. So let's say you're looking to encode the state of a column containing [0, 1, 0, 0, 0, 0, 0]. The best thing would be to make the original matrix a boolean matrix, and use findall on the column:

在Julia中,通常按列操作比按行操作更好,因为它是以列为主的语言。因此,假设您希望对包含[0,1,0,0,0,0,0,0]的列的状态进行编码。最好的方法是使原始矩阵成为布尔矩阵,并在列上使用findall:


julia> M = BitArray([1 0 1 0
0 1 0 1
1 0 0 1
0 0 1 0
1 0 0 1
1 0 1 1
0 0 0 1])
7×4 BitMatrix:
1 0 1 0
0 1 0 1
1 0 0 1
0 0 1 0
1 0 0 1
1 0 1 1
0 0 0 1

julia> col = @view M[:, 2]
7-element view(::BitMatrix, :, 2) with eltype Bool:
0
1
0
0
0
0
0

julia> only(findall(col))
2

Note that Julia uses 1-based indexes for arrays, so it would be more convenient to decode the state you've given to 2 rather than 1 - because the 1 is in the 2nd position in the column. If you do need it to be 1 for some other reason, you can of course do only(findall(col)) - 1

请注意,Julia对数组使用从1开始的索引,因此将您给出的状态解码为2比1更方便--因为1位于列中的第二个位置。如果出于某种其他原因,您确实需要它为1,那么您当然可以只使用(findall(Ol))-1


更多回答

I'm trying to convert both rows and columns to indexes. In addition to (0100000), there are many other states (0230000), (6300000), and so on, and we want to specify each matrix value by placing various states in rows and columns. For example The row is (6010010) and the column is (5000000), and I want to put 0.004 in this position. At this point, if you specify the index for the (6010010) and (5000000) status values and the index is 1 row and 1 column, you want to express (1,1) = 0.004. I'm curious how to index the status of rows and columns here.

我正在尝试将行和列都转换为索引。除了(0100000)之外,还有许多其他状态(0230000)、(6300000)等等,我们希望通过在行和列中放置各种状态来指定每个矩阵值。例如,行是(6010010),列是(5000000),我想把0.004放在这个位置。此时,如果您为(6010010)和(5000000)状态值指定索引,并且该索引为1行1列,则您希望EXPRESS(1,1)=0.004。我很好奇如何在这里索引行和列的状态。

Sorry, I don't understand that at all. My answer was assuming that you had something like a simple one-hot encoding, and wanted to decode that. It doesn't seem like that's the case, so please add more details to the question, including Julia code and output, about what data you have right now, in what kinds of variables.

对不起,我一点也不明白。我的回答是假设你有一个简单的热编码,并想要解码它。情况似乎并非如此,所以请在问题中添加更多细节,包括Julia代码和输出,关于您现在拥有哪些数据,在哪些类型的变量中。

If I had to take a guess, maybe you're looking for github.com/mcabbott/AxisKeys.jl , a way to give names ("state values") to the rows and columns and index using them?

如果让我猜一猜,也许您正在寻找githorb.com/mCabbott/AxisKeys.jl,一种为行和列指定名称(“状态值”)并使用它们进行索引的方法?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com