亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我怎樣才能通過張量并獲得我想要的位置的值?

我怎樣才能通過張量并獲得我想要的位置的值?

www說 2024-01-27 16:11:00
例如,我有這個張量:Boxes(tensor([[ 138.7087,  670.4597,  194.0305,  788.7614],    [1744.7915,  597.5836, 1790.3419,  709.9775],    [ 384.6486,  526.4615,  428.3247,  622.8542],    [1396.4264,  562.2295, 1444.1472,  653.7578],    [1135.2161,  504.2900, 1169.5103,  608.7569],    [1035.7961,  771.2336, 1100.9679,  919.1385],    [ 696.5236,  419.2245,  738.7255,  503.7422],    [  63.7905,  362.0703,   93.2846,  439.7708],    [ 834.4216,  591.6379,  880.6455,  690.0402],    [1003.2484,  612.4662, 1055.1136,  704.1541],    [ 852.7735,  330.7743,  879.5329,  396.9597],    [ 840.9529,  526.4127,  871.9255,  594.8165],    [ 798.7436,  520.0127,  834.4247,  601.9252],    [1539.8649,  600.5634, 1576.6362,  679.7695],    [ 151.1197,  366.5715,  186.4236,  434.6742],    [ 152.5436,  322.7310,  196.8471,  429.3589],    [ 164.2602,  322.5941,  195.3645,  386.3824]], device='cuda:0'))我想獲取每行的所有 for 值并將其寫入不同的變量,這怎么可能?
查看完整描述

3 回答

?
largeQ

TA貢獻2039條經驗 獲得超8個贊

import tensorflow as tf


a = tf.convert_to_tensor([

    [ 138.7087,  670.4597,  194.0305,  788.7614],

    [1744.7915,  597.5836, 1790.3419,  709.9775],

    [ 384.6486,  526.4615,  428.3247,  622.8542],

    ...

    [ 152.5436,  322.7310,  196.8471,  429.3589],

    [ 164.2602,  322.5941,  195.3645,  386.3824]

])


b = tf.unstack(a, axis=0)


查看完整回答
反對 回復 2024-01-27
?
慕村225694

TA貢獻1880條經驗 獲得超4個贊

假設t是你的張量對象。


ax1 = t.shape[1]


for i in range(ax1):

    vals = t[:,i]

    # do stuff


查看完整回答
反對 回復 2024-01-27
?
白衣非少年

TA貢獻1155條經驗 獲得超0個贊

用于tf.split()獲取張量列表(每行一個):


boxes = tf.constant([[ 138.7087,  670.4597,  194.0305,  788.7614],

    [1744.7915,  597.5836, 1790.3419,  709.9775],

    [ 384.6486,  526.4615,  428.3247,  622.8542],

    [1396.4264,  562.2295, 1444.1472,  653.7578],

    [1135.2161,  504.2900, 1169.5103,  608.7569],

    [1035.7961,  771.2336, 1100.9679,  919.1385]],)


tf.split(boxes, num_or_size_splits=boxes.shape[0], axis = 0)


[<tf.Tensor: shape=(1, 4), dtype=float32, numpy=array([[138.7087, 670.4597, 194.0305, 788.7614]], dtype=float32)>,

 <tf.Tensor: shape=(1, 4), dtype=float32, numpy=array([[1744.7915,  597.5836, 1790.3419,  709.9775]], dtype=float32)>,

 <tf.Tensor: shape=(1, 4), dtype=float32, numpy=array([[384.6486, 526.4615, 428.3247, 622.8542]], dtype=float32)>,

 <tf.Tensor: shape=(1, 4), dtype=float32, numpy=array([[1396.4264,  562.2295, 1444.1472,  653.7578]], dtype=float32)>,

 <tf.Tensor: shape=(1, 4), dtype=float32, numpy=array([[1135.2161,  504.29  , 1169.5103,  608.7569]], dtype=float32)>,

 <tf.Tensor: shape=(1, 4), dtype=float32, numpy=array([[1035.7961,  771.2336, 1100.9679,  919.1385]], dtype=float32)>]



查看完整回答
反對 回復 2024-01-27
  • 3 回答
  • 0 關注
  • 240 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號