2017-09-08 14 views
2

(N,2,2)의 2D 회전 행렬로 R이 있습니다. 이제 각각의 행렬을 (3,3) 차원 회전 행렬로 확장하여 각 [:,:2,:2]에 0을 넣고 1[:,2,2]에 입력하고 싶습니다.메인 대각선과 제로에서 하나씩 복수의 텐서를 패딩하는 방법은 무엇입니까?

tensorflow에서 이것을 수행하는 방법은 무엇입니까?

UPDATE concat은 방송하지 않기 때문에 나는이 방법

R = tf.get_variable(name='R', shape=np.shape(R_value), dtype=tf.float64, 
         initializer=tf.constant_initializer(R_value)) 
    eye = tf.eye(np.shape(R_value)[1]+1) 
    right_column = eye[:2,2] 
    bottom_row = eye[2,:] 
    R = tf.concat([R, right_column], 3) 
    R = tf.concat([R, bottom_row], 2) 

을 시도했지만 실패

...

업데이트 2

내가 명시 적으로 만든 방송 및 잘못된 고정 색인도 concat 전화 :

R = tf.get_variable(name='R', shape=np.shape(R_value), dtype=tf.float64, 
         initializer=tf.constant_initializer(R_value)) 
    eye = tf.eye(np.shape(R_value)[1]+1, dtype=tf.float64) 

    right_column = eye[:2,2] 
    right_column = tf.expand_dims(right_column, 0) 
    right_column = tf.expand_dims(right_column, 2) 
    right_column = tf.tile(right_column, (np.shape(R_value)[0], 1, 1)) 

    bottom_row = eye[2,:] 
    bottom_row = tf.expand_dims(bottom_row, 0) 
    bottom_row = tf.expand_dims(bottom_row, 0) 
    bottom_row = tf.tile(bottom_row, (np.shape(R_value)[0], 1, 1)) 

    R = tf.concat([R, right_column], 2) 
    R = tf.concat([R, bottom_row], 1) 

솔루션이 다소 복잡해 보입니다. 더 간단한 것이 있습니까? [N, 2, 2]

답변

0

첫번째 패드 제로 다음 padded[N, 2, 2] 1 변환 padded = tf.pad(R, [[0, 0], [0, 1], [0, 1]])

[N, 3, 3] 수 : 할당을 지원하지 않습니다

tf.Tensor 이후, 당신은 np.array를 초기화하여이 작업을 수행 한 다음 함께 추가 할 수 있습니다. R

arr = np.zeros((3, 3)) 
arr[2, 2] = 1 
R = padded + arr # broadcast used here 

이제 변수는

을 필요로하는 무슨이다