简体   繁体   English

如何将 numpy 数组的每一行向量与其自身和每个元素进行比较

[英]How to compare each row of vectors of numpy array to itself and every element

I have a numpy array which contains vectorised data.我有一个包含矢量化数据的 numpy 数组。 I need to compare each of these vectors (a row in the array) euclidean distances to itself and every other row.我需要比较这些向量中的每一个(数组中的一行)欧几里得距离自身和每隔一行。

The vectors are of the form向量的形式为

[[0 0 0 ... 0 0 0]
 [0 0 0 ... 0 0 0]
 [0 0 0 ... 0 0 0]
 ...
 [0 0 0 ... 0 0 0]
 [0 0 0 ... 0 0 0]
 [0 0 0 ... 0 0 0]]

I know I need two loops, here is what I have so far我知道我需要两个循环,这是我目前所拥有的

def euclidean_distance_loop(termdoc):
    i = 0
    j = 0
    matrix = np.array([])
    while( j < (len(termdoc-1))):
        matrix = np.append(matrix,[euclidean_distance(termdoc[i],termdoc[j])])
        j = j + 1
        
    return np.array([matrix])

euclidean_distance_loop(termdoc)

I know this is an index problem and I need another index or an incremented index in another loop but not sure how to construct it我知道这是一个索引问题,我需要另一个索引或另一个循环中的递增索引,但不知道如何构造它

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何相对于自身缩放 numpy 数组的每个元素? - How do I scale each element of a numpy array relative to itself? 如何展平 numpy 结构化数组,其中每个元素本身都是 numpy 数组(dtype='O') - How to flatten a numpy structured array where each element is itself a numpy array (dtype='O') 比较一个numpy数组和另一个数组的每个元素 - Compare a numpy array to each element of another one 比较 numpy 数组中每个元素的矢量化方法 - vectorized way to compare each element in numpy array 如何为numpy数组变量中的每一行制作不同的元素? - How to make different element for each row in numpy array variable? 更新 numpy 数组中每一行的最后一个元素 - Update last element of each row in numpy array 在 Python 中,如何将 numpy 数组与矩阵的每一行进行比较以选择与向量最相似的行? - In Python, how can I compare a numpy array to each row of a matrix to chose the row that is most similar to the vector? 将 numpy 数组与矩阵的每一行进行比较以计算相似项(矢量化) - Compare numpy array to every row of matrix to count similar items (vectorized) 将一个数组的每一行与numpy中另一个数组的每个元素相乘 - Multiply each row of one array with each element of another array in numpy 如何在numpy中将数组的每个元素与另一个没有循环的整个数组进行比较 - How to compare each element of an array with another entire array without loops in numpy
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM