给定长度为L的一维张量T,它只有N个不同的值,如何将其转换为长度为L的张量T2,其值在0到N-1之间,与原始张量T的值相对应。 示例:
@Entity
@Table(name = "users")
public class UsuarioEntity implements Serializable {
@Id
private String username;
@Column(length = 60, unique = true)
private String password;
@OneToOne(fetch = FetchType.LAZY)
@JoinTable(name="authorities",
joinColumns = @JoinColumn(name="username")
)
private RoleEntity roles;
排序并不重要,例如,这也可以:
T = [45, 58, 72, 33, 45, 58, 58, 33]
T2 = [ 0, 1, 2, 3, 0, 1, 1, 3]
答案 0 :(得分:1)
也许尝试:
tf.unique(T)[1]
tf.unique_with_counts(T)[1]