第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

取一個張量的元素,它也在另一個張量中

取一個張量的元素,它也在另一個張量中

手掌心 2021-07-06 12:08:56
我有兩個張量,我必須迭代第一個以只取另一個張量內(nèi)的元素。只有一個元素t2也在里面t1。這里有一個例子t1 = tf.where(values > 0) # I get some indices example [6, 0], [3, 0]t2 = tf.where(values2 > 0) # I get [4, 0], [3, 0]t3 = .... # [3, 0]我嘗試使用運(yùn)算符來評估和迭代它們,.eval()并檢查它們是否t2正在t1使用 operator in,但不起作用。TensorFlow 有沒有可以做到這一點(diǎn)的函數(shù)?編輯for index in xrange(max_indices):    indices = tf.where(tf.equal(values, (index + 1))).eval() # indices: [[1 0]\n [4 0]\n [9 0]]    cent_indices = tf.where(centers > 0).eval() # cent_indices: [[6 0]\n [9 0]]    indices_list.append(indices)    for cent in cent_indices:        if cent in indices:           centers_list.append(cent)           break第一次迭代cent具有值[6 0]但它進(jìn)入if條件?;卮餱or index in xrange(max_indices):    indices = tf.where(tf.equal(values, (index + 1))).eval()    cent_indices = tf.where(centers > 0).eval()    indices_list.append(indices)    for cent in cent_indices:        # batch_item is an iterator from an outer loop        if values[batch_item, cent[0]].eval() == (index + 1):           centers_list.append(tf.constant(cent))           break該解決方案與我的任務(wù)有關(guān),但如果您正在尋找一維張量中的解決方案,我建議您查看 tf.sets.set_intersection
查看完整描述

1 回答

?
炎炎設(shè)計(jì)

TA貢獻(xiàn)1808條經(jīng)驗(yàn) 獲得超4個贊

那是你想要的嗎?我只使用了這兩個測試用例。


x = tf.constant([[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 1]])

y = tf.constant([[1, 2, 3, 4, 3, 6], [1, 2, 3, 4, 5, 1]])

# x = tf.constant([[1, 2], [4, 5], [7, 7]])

# y = tf.constant([[7, 7], [3, 5]])


def match(xiterations, yiterations, yvalues, xvalues ):

    for i in range(xiterations):

        for j in range(yiterations):

            if (np.array_equal(yvalues[j], xvalues[i])):

                print( yvalues[j])


with tf.Session() as sess:

    xindex = tf.where( x > 4 )

    yindex = tf.where( y > 4 )


    xvalues = xindex.eval()

    yvalues = yindex.eval()


    xiterations =  tf.shape(xvalues)[0].eval()

    yiterations =  tf.shape(yvalues)[0].eval()


    print(tf.shape(xvalues)[0].eval())

    print(tf.shape(yvalues)[0].eval())


    if tf.shape(xvalues)[0].eval() >= tf.shape(yvalues)[0].eval():

        match( xiterations, yiterations, yvalues, xvalues)

    else:

        match( yiterations, xiterations, xvalues, yvalues)


查看完整回答
反對 回復(fù) 2021-07-21
  • 1 回答
  • 0 關(guān)注
  • 245 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號