[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-list
Subject:    Newbie question
From:       Joe Hays <joey_hays () hotmail ! com>
Date:       2008-11-06 21:14:08
Message-ID: BAY136-W533CCEA8B2E06E09ACE6178A1E0 () phx ! gbl
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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?

Joe


_________________________________________________________________
Windows Live Hotmail now works up to 70% faster.
http://windowslive.com/Explore/Hotmail?ocid=TXT_TAGLM_WL_hotmail_acq_faster_112008


[Attachment #5 (text/html)]

<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
</style>
</head>
<body class='hmmessage'>
I'm a newbie to python. Can anyone tell me why the following little program complains \
about incorrect dimensions?<br><br>&lt;snip&gt;<br><blockquote>import pylab<br>from \
pylab import *<br><br>n = 10; m = 2*n;<br>A = randn(m,n);<br>b = A*rand(n,1) + \
2*rand(m,1);<br></blockquote>&lt;/snip&gt;<br><br>The actual error I receive \
is,<br><br>&lt;snip&gt;<br><blockquote>b = A*rand(n,1) + 2*rand(m,1);<br>ValueError: \
shape mismatch: objects cannot be broadcast to a single \
shape<br></blockquote>&lt;/snip&gt;<br><br>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.<br><br>Ideas?<br><br>Joe<br><br><br /><hr />Windows Live Hotmail now works up \
to 70% faster. <a href='http://windowslive.com/Explore/Hotmail?ocid=TXT_TAGLM_WL_hotmail_acq_faster_112008' \
target='_new'>Sign up today.</a></body> </html>



--
http://mail.python.org/mailman/listinfo/python-list


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic