【发布时间】:2021-10-09 18:19:21
【问题描述】:
我收到了这个函数的 AssertionError ... 我该如何解决这个问题
def one_hot_matrix(label, depth=6):
one_hot = tf.one_hot(label, depth, axis = 0)
one_hot = tf.reshape(one_hot, (-1,1))
return one_hot
def one_hot_matrix_test(target):
label = tf.constant(1)
depth = 4
result = target(label, depth)
print("Test 1:",result)
assert result.shape[0] == depth, "Use the parameter depth"
assert np.allclose(result, [0., 1. ,0., 0.] ), "Wrong output. Use tf.one_hot"
label_2 = [2]
result = target(label_2, depth)
print("Test 2:", result)
assert result.shape[0] == depth, "Use the parameter depth"
assert np.allclose(result, [0., 0. ,1., 0.] ), "Wrong output. Use tf.reshape as instructed"
print("\033[92mAll test passed")
【问题讨论】:
-
请提供一些示例输入和错误。
-
嗨!请提供完整的代码和错误详情,以帮助我们理解问题。
标签: python tensorflow one-hot-encoding