-2

I am looking for a way to represent 2 same dimension vectors as 1 like summation of corresponding elements of vector.

EDIT

I have 5 vectors from 5 word embedding models(string2vec, word2vec, doc2vec, topic2vec, and glove2vec) and now I want to combine them to form one representational vector to be fed into ml classification models. I have tried addition, multiplication, mean, median and distance formula. I am looking for techniques to join vectors other than the ones i mentioned

Rodrigo Souza
  • 7,162
  • 12
  • 41
  • 72
  • Hey, welcome to SO. Can you edit your question to include how you want to represent a vector? There are multiple ways and knowing would make it easier to answer your question. If you use NumPy you might want to check out [`numpy.add`](https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.add.html) regardless. – blkpingu Oct 12 '19 at 17:42
  • Thank you for understanding. I know about numpy.add, I am looking for ways other than add like we can have mean value of corresponding entities of vectors. –  Oct 12 '19 at 17:54
  • Feel free to give an elaborate example. I know it's a hassle to be elaborate, but it really makes it easier to understand the question better. Post screenshots of the exact math you want to do, maybe write them up in LaTeX. Show us what you tried. Tell us why it didn't work and where you are stuck. – blkpingu Oct 12 '19 at 18:05
  • Okay so i am trying to understand Does the method of joining 2 vectors as 1 (same dimensions) using multiple techniques effect the accuracy of system. If so by how much and which method is better than the other. I have vectors from 5 word embedding models(string2vec, word2vec, doc2vec, topic2vec, and glove2vec) and now i want to combine them to form one representational vector to be fed into ml classification models.. i have tried add, multiply, mean, median and distance formula.. what are the standard other ways to do so? Sorry if it confuses you more –  Oct 12 '19 at 18:13
  • Possible duplicate of [Concise vector adding in Python?](https://stackoverflow.com/questions/845112/concise-vector-adding-in-python) – blkpingu Oct 12 '19 at 18:17
  • @TobiasKolb no this is not what i am asking –  Oct 12 '19 at 18:20
  • Please make it clear what **exactly** you are asking. “I am looking for techniques” is not a valid question. Elaborate. – blkpingu Oct 12 '19 at 18:22
  • Can you add an example for each of you 5 vectors contents and what a preferred form of “combination” would look like? I have an ML background myself and I have no idea what you are trying to do. – blkpingu Oct 12 '19 at 18:25
  • What kind of classifier do you use, which library do you use, what kind of data do you use. Please post some code and samples of your data and a more elaborate explanation what you are trying to classify and how. – blkpingu Oct 12 '19 at 18:33
  • I think i messed up.. You have vec A=[1,2] and vec B=[3,4] now to get C = combination of A & B and this combination can be sum, mean, multiplication, distance formula etc.. I cannot elaborate it more.. If it doesn't make sense please ignore and sorry for wasting your time –  Oct 12 '19 at 18:34

3 Answers3

1

Your Question is incomplete. As far as I can understand you are willing to do operations on the vectors element-wise. Let the two vectors be

arr1=np.array([1,2,3])

and

arr2=np.array([4,5,6])

So, simple addition and subtraction element-wise can be done as arr1+arr2 or arr1-arr2. For element wise multiplication of the above vectors, you can use np.multiply(arr1,arr2) like syntax.

Hope it can help you. Else state your question clearly.

Rudresh Dixit
  • 320
  • 1
  • 4
  • 15
  • Thank you. Yes I want to do operations on the vectors element wise like Sum, Subtraction, Multiplication, Mean, Median, Distance formula... Where multiple values can be represented as one.. basically looking for techniques –  Oct 12 '19 at 18:00
  • 1
    Mean and median are the properties of the whole vector not for a single element. You can use `np.mean(arr1)` and `np.median(arr1)` for this purpose. If you find the answer helpful please do mark the tick on left to green. – Rudresh Dixit Oct 12 '19 at 18:14
  • [What should I do when someone answers my question?](https://stackoverflow.com/help/someone-answers) – blkpingu Oct 12 '19 at 18:16
1

Having the same dimension does not guarantee identical features / structure among multiple models. In fact adding vectors for the same word from 2 different Doc2Vec models would probably be meaningless.

That being said, it might be interesting concatenating (some of) them and feeding them as input to another deep network. Ie: build and entirely new model.

This thread might help as well. https://groups.google.com/g/gensim/c/N5SCiq1F45w/m/QqVuoTUYCQAJ

Cristian Dumitru
  • 321
  • 1
  • 3
  • 5
0

Using Numpy, you can do element wise operation very easily.

import numpy as np 

a = np.ones((3,3))
b = np.ones((3,3))
c = a + b

Same goes to other operation. - , *, / (division is a bit more tricky)

J_yang
  • 2,672
  • 8
  • 32
  • 61