简体   繁体   English

将张量转换为矢量

[英]Transform Tensor to a vector

I have a tensor with shape: 我有一个张量形状:

2 x 2 x 3 x 2 2 x 2 x 3 x 2

namely: {player, round, number of raises, action taken} 即:{玩家,回合,加注次数,采取的行动}

It's a two player game, which ends after two rounds while maximum 3 raises can be done and each raise contains the information about the taken action. 这是一个两人游戏,在两轮之后结束,最多可以进行3次加注,每次加注都包含有关已采取行动的信息。

I want to create an array which represents every step of the game. 我想创建一个代表游戏每一步的数组。 So i have the information about every players action for each raise, for each round. 因此,我可以获得有关每个加薪,每个回合的每个球员动作的信息。

Is there any possibility to do something like this: 有没有可能做这样的事情:

players = array[0, 1]
rounds = array[2, 3]
raises = array[4, 5, 6]
actions = array[7, 8]

niceAndHandyArray = someFunction(players, rounds, raises, actions)
# Which outputs something like this:
[
    [0, [
            2, [
                   4, [7, 8]
                ],
            ...
        ],
    [1, 
         ... 
    ]
]

# And then access it like:
niceAndHandyAcrray[player_index][round_index][raise_index][action_index] = 1

# And pass it to my neural network later on as:
niceAndHandyArray.flatten()

Try use reshape : 尝试使用reshape

#Example:
# tensor 't' is [[[1, 1, 1],
#                 [2, 2, 2]],
#                [[3, 3, 3],
#                 [4, 4, 4]],
#                [[5, 5, 5],
#                 [6, 6, 6]]]
# tensor 't' has shape [3, 2, 3]
# pass '[-1]' to flatten 't'
tf.reshape(t, [-1])
#output: [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM