473,387 Members | 1,348 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Props to numpy programmers!

So I wanted to matrixmultiply

[[a,b],
[c,d]]

*

[e,f]

Of course this is impossible, because the number of columns in the
first factor is not equal to the number of rows in the second. Wrong!
It is impossible because the second matrix is rank1! So numpy
happily converts it to a column vector so the multiplication will
work, and converts the answer back into a rank1 vector!!!!

I love NUMPY!!!!!!!!!!!

I was reading my code and thought I had a bug, I couldn't figure out
why the code was still working right! It's because the numpy people
are geniouses!

Hooray numpy!!!!!!!!!! Numpy is smarter than me!
Jul 18 '05 #1
1 1787

"Andrew Felch" <an*********@yahoo.com> wrote in message
news:9e**************************@posting.google.c om...
So I wanted to matrixmultiply

[[a,b],
[c,d]]

*

[e,f]

Of course this is impossible, because the number of columns in the
first factor is not equal to the number of rows in the second. Wrong!
It is impossible because the second matrix is rank1! So numpy
happily converts it to a column vector so the multiplication will
work, and converts the answer back into a rank1 vector!!!!

I love NUMPY!!!!!!!!!!!

I was reading my code and thought I had a bug, I couldn't figure out
why the code was still working right! It's because the numpy people
are geniouses!

Hooray numpy!!!!!!!!!! Numpy is smarter than me!


I love Numpy too. But I wouldn't want this multiplication to work if the
second array was a row vector (and there's no explicit distinction because
of the array's shape).
a array([[0, 1],
[2, 3]]) b array([4, 5]) Numeric.matrixmultiply(a,b) array([ 5, 23]) Numeric.matrixmultiply(b,a) array([10, 19])

One of these multiplications should fail, depending on whether b is a column
or row vector.

Make it a column vector by reshaping,
b = Numeric.reshape(b, (2,1))
b array([[4],
[5]])

and it does the right thing.
Numeric.matrixmultiply(a,b) array([[ 5],
[23]]) Numeric.matrixmultiply(b,a)
Traceback (most recent call last):
File "<pyshell#60>", line 1, in -toplevel-
Numeric.matrixmultiply(b,a)
File "C:\Python23\lib\site-packages\Numeric\Numeric.py", line 335, in dot
return multiarray.matrixproduct(a, b)
ValueError: matrices are not aligned


Much safer IMHO.

Duncan

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Arno R | last post by:
Hi there, I just distributed an application in which I (try to) change db.properties depending on CurrentUser() For instance I set the property's AllowBypassKey and AllowBuiltinToolbars to False...
13
by: Arno R | last post by:
Hi all In another thread I had problems changing db.props Another problem I encountered while testing this: db corrupt When I deleted db.props through code in a loop I could not start the db again...
13
by: Gary Wessle | last post by:
Hi I am trying to install NumPy in my debian/testing linux 2.6.15-1-686. with no numpy for debian/testing, I am left alone, since the experimental version available by debian will result in a...
3
by: Iljya | last post by:
Hello, I need to pickle the type numpy.float32 but encounter an error when I try to do so. I am able to pickle the array itself, it is specifically the type that I cannot pickle. I am using:...
0
by: robert | last post by:
just a note - some speed comparisons : 0.60627370238398726 0.42836673376223189 0.36965815487747022 0.016557970357098384 0.15692469294117473 0.01951756438393204
2
by: Chris Smith | last post by:
Howdy, I'm a college student and for one of we are writing programs to numerically compute the parameters of antenna arrays. I decided to use Python to code up my programs. Up to now I haven't...
5
by: robert | last post by:
Turning algs for old NumPy modules into numpy code I suffer from this: Upon further processing of returns of numpy calculations, lots of data in an apps object tree will become elementary numpy...
8
by: Grant Edwards | last post by:
How do you print a numpy array? I tried the obvious print a, print `a`, and print str(a), but none of them work on anything other than trivially small arrays. Most of my real data is elided and...
2
by: Travis Oliphant | last post by:
I wanted to point anybody interested to a blog post that describes a useful pattern for having a NumPy array that points to the memory created by a different memory manager than the standard one...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.