473,322 Members | 1,736 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,322 software developers and data experts.

Re: Newbie question

Joe Hays wrote:
I'm a newbie to python. Can anyone tell me why the following little
program complains about incorrect dimensions?

<snip>

import pylab
from pylab import *

n = 10; m = 2*n;
A = randn(m,n);
b = A*rand(n,1) + 2*rand(m,1);

</snip>

The actual error I receive is,

<snip>

b = A*rand(n,1) + 2*rand(m,1);
ValueError: shape mismatch: objects cannot be broadcast to a single
shape

</snip>

This is supposed to be doing a matrix multply of an (m,n)(n,1). This
results in an (m,1). This should then be able to be added to the
2*rand(m,1), but, its not for some reason.

Ideas?
You will want to ask numpy questions on the numpy mailing list (preferably with
a subject line a bit more informative with respect to the actual problem).

http://www.scipy.org/Mailing_Lists

In this case, the problem is that * does not do matrix multiplication; it does
element-wise multiplication. Use dot(A, randn(n,1)) instead.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Nov 6 '08 #1
0 1197

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

Similar topics

0
by: Elger | last post by:
Dear Members, A newbie question How do I convert this XML example into HTML (using XSLT)? <DOCUMENT> <PARA> This <BOLD>is</BOLD> a <BOLD>test</BOLD> </PARA> </DOCUMENT>
4
by: DragonLord | last post by:
I have a custom user control that i am trying to understand and it has numbers before the line items. So here it comes the real newbie question What the heck are the numbers for?? 205: For...
5
by: kamikaze04 | last post by:
Hello. I have a very newbie question about Streams. The situation is that i have a function (that i cannot modify it's definition/call): public void F1(istream & in){ while( ...) { ...
5
by: Banibrata Dutta | last post by:
Hi, I've gone through the list of "language differences" between 2.3 / 2.4 & 2.5 of CPython. I've spend around 2 weeks now, learning v2.5 of CPython, and I consider myself still very very...
16
by: Raxit | last post by:
Hi, i was reading/learning some hello world program in python. I think its very simillar to Java/C++/C#. What's different (except syntax) ? what can i do easily with python which is not easy...
7
by: idiolect | last post by:
Hi all - Sorry to plague you with another newbie question from a lurker. Hopefully, this will be simple. I have a list full of RGB pixel values read from an image. I want to test each RGB band...
5
by: Randall | last post by:
I am a newbie trying to learn the DOM. Can someone tell me why the first alert statement returns null, and the second returns the value 33px (which was set using the style="top:33px;" in the DIV...
12
by: Philipp.Weissenbacher | last post by:
Hi all! This is most certainly a total newbie question, but why doesn't the following code cause a segfault? void insertion_sort(int a, int length) { int i; for (i=0; i < length; i++) { int...
3
Lokean
by: Lokean | last post by:
Sorry for this newbie question, this is not my realm of expertese. I have searched google, tried several applications that claim they can do this, such as Mapforce, which I found confusing, to...
5
by: Dave | last post by:
I am new to Visual Web Developer 2005 Expres. I am using absolute positioning and every time I add a button control to my web form its width extends all the way to the edge of the page. IOW I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.