我有一个形状为(32,1024,40,3)
的张量和一个大小为40的阶跃函数矢量(即[1,1,1,...,1,0,0,...,0]
),我想在给定轴内将矩阵相乘。
这是我的代码,第716行有错误'Tensor' object does not support item assignment
:
def weight_knn(dist_from_point, weight_param):
given_axis = dist_from_point.shape[-2]
step = np.ones(given_axis)
step[weight_param:] = 0
dim_array = tf.reshape(tf.ones((1, tf.rank(dist_from_point)),tf.uint16),[-1])
dim_array[-2] = -1
step_reshaped = step.reshape(dim_array)
return dist_from_point*step_reshaped
this numpy snippet采纳了沿特定轴进行乘法的想法
并且目标是能够在给定的暗度下使用多暗度张量来实现阶跃功能