How can I differentiate between column vectors and row vectors using Python

0 votes

Hi all, my question is simple. All I wanted to know was if there was a recommended way which is used to differentiate between the column vectors and the row vectors using Python?

Up until now, I use SciPy and NumPy and I know when I have to give a single vector something like this:

from numpy import *
Vector = array([5,6,7])

This will not tell me if it's a column or a row vector, correct?

And also, check out the following piece of code:

array([5,6,7]) == array([5,6,7]).transpose()
True

This is not possible, right? Differentiation is not needed for the functions on the mentioned modules is what I already know of.

Consider this, outer(a,b) or say even a.dot(b) - But then it would be nicer if I could differentiate it at my own convenience, don't you think?

All help appreciated!

Jan 23, 2019 in Python by Anirudh
• 2,090 points

edited Jan 23, 2019 by Anirudh 2,178 views

1 answer to this question.

0 votes

Hi, good question. What you can do to fix this is to make it explicit to forcing on the dimension to the array. 

Check out the following piece of code for clarity:

>>> a = np.array([5, 6, 7])
>>> a
array([5, 6, 7])
>>> a.transpose()
array([5, 6, 7])
>>> a.dot(a.transpose())
14

 Now, you use the column vector for specificity and you make sure that it is forced upon and used.

Check out the below code:

>>> a.shape = (3,1)
>>> a
array([[5],
       [6],
       [7]])
>>> a.transpose()
array([[5, 6, 7]])
>>> a.dot(a.transpose())
array([[1, 2, 3],
       [2, 4, 6],
       [3, 6, 9]])


Hope this helped!

answered Jan 23, 2019 by Nymeria
• 3,560 points

Related Questions In Python

0 votes
1 answer

How can I find out the index of an element from row and column in Python?

You probably want to use np.ravel_multi_index: [code] import numpy ...READ MORE

answered Apr 16, 2018 in Python by charlie_brown
• 7,720 points
2,338 views
0 votes
1 answer

How do I create 3 X 4 array of random numbers between 0 and 100 using python?

Use numpy in the following manner: np.random.rand(3,4)*100 When you ...READ MORE

answered May 24, 2019 in Python by Radhika
2,257 views
0 votes
0 answers
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,068 views
0 votes
1 answer

Removing surrounding whitespace

Try the strip() function:  s = s.strip() If you ...READ MORE

answered May 4, 2018 in Python by Nietzsche's daemon
• 4,260 points
777 views
0 votes
1 answer

How can I have only positive decimal numbers in Django using Python?

Hi, are you aware of something called ...READ MORE

answered Jan 30, 2019 in Python by Nymeria
• 3,560 points
6,300 views
0 votes
1 answer

How can I lookup hostname using the IP address with a timeout in Python?

Good question. I actually was stuck with ...READ MORE

answered Feb 6, 2019 in Python by Nymeria
• 3,560 points
2,565 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP