我可以知道如何在java中对两个向量求和吗?
public void CosineSimilarity(ArrayList<Integer> h,String a, Object[] array) throws Exception {
Vector value = new Vector();
double cos_sim=(cosine_similarity(vec1,vec2))*60/100;
System.out.println(cos_sim); //I get [0.333] and [0.358]
value.add(cos_sim);
CompareType(value,a,array);
}
这里是CompareType函数
public void CompareType(Vector value,String a,Object[] array ) throws Exception {
// TODO Auto-generated method stub
String k;
double c = 0;
String sql="Select Type from menu ";
DatabaseConnection db = new DatabaseConnection();
Connection conn =db.getConnection();
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
Vector value1 = new Vector();
while (rs.next())
{
k=rs.getString("Type");
if(a.equals(k))
{
c=10.0/100;
value1.add(c);
}
else
{
c=0;
value1.add(c);
}
}
System.out.println(value1); // I get [0.0] and [0.1]
Sum(value,value1);
ps.close();
rs.close();
conn.close();
}
我应该在下面的函数中写什么,这样可以将两个值向量相加并返回两个总值?
private void Sum(Vector value, Vector value1) {
// TODO Auto-generated method stub
}