简体   繁体   中英

accessing 2d numpy arrays

I have a list of labels and numpy arrays like below. I want to measure the distance between the arrays only using the euclidean distance.

    ('red', array([ 0.,  0.,  0., ...,  0.,  0.,  1.]))
    ('blue', array([ 0.,  0.,  0., ...,  0.,  0.,  1.]))

I will use something like dist = numpy.linalg.norm(arrayVec1-ArrayVec2)

How can I specify only the array parts([ 0., 0., 0., ..., 0., 0., 1.])) and array([ 0., 0., 0., ..., 0., 0., 1.])) excluding the labels red and blue for the euclidean distance measure?

You can do this:

x= ('red', array([ 0.,  0.,  0.,  0.,  0.,  1.]))
y= ('blue', array([ 0.,  0.,  0., 0.,  0.,  1.]))

np.linalg.norm(x[1]-y[1])

Note.

print x[1]

gives:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM