<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div name="messageBodySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;"><font face="Helvetica">There are a couple of interesting observations here.  In your first bit, you have:</font>
<div><font face="Helvetica"><br /></font></div>
<div>
<blockquote type="cite" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #1abc9c;">
<div class="pre" style="margin: 0px; padding: 0px;"><font face="Helvetica">## works with a row vector<br />
vect0 = np.random.rand(5)</font></div>
<div class="pre" style="margin: 0px; padding: 0px;"><font face="Helvetica">mat[:,0]=np.transpose(vect0)<br /></font></div>
</blockquote>
<font face="Helvetica"><br /></font></div>
<div><font face="Helvetica">(or I prefer vect0.T).  Did you happen to notice that this works too:</font></div>
<div><font face="Helvetica"><br /></font></div>
<div>
<blockquote type="cite" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #1abc9c;">
<div class="pre" style="margin: 0px; padding: 0px;"><font face="Helvetica">mat[:,0]=vect0</font></div>
<div class="pre" style="margin: 0px; padding: 0px;"><font face="Helvetica"><br /></font></div>
</blockquote>
<font face="Helvetica"><br /></font></div>
<div><font face="Helvetica">The transpose or the original work as well.  Unlike Scilab, python’s arrays can be literally 1-dimensional.  Not 5x1 but just 5,  which doesn’t have a transpose, because it doesn’t have a 2nd dimension.</font></div>
<div><font face="Helvetica"><br /></font></div>
<div><font face="Helvetica">you can see that in vect0.shape</font></div>
<div><font face="Helvetica"><br /></font></div>
<div><font face="Helvetica">so np.random.rand(5) doesn’t make a row-vector but a length 5 array, which is different than </font><span style="font-family: Helvetica;">np.random.rand(5,1) or </span><span style="font-family: Helvetica;">np.random.rand(1,5).  Thus, you have to make sure the shapes all work. </span></div>
<div><span style="font-family: Helvetica;"><br /></span></div>
<div><font face="Helvetica">in your second example, with the column vector, you can also slice along the 2nd dimension without transposing like:</font></div>
<div><font face="Helvetica"><br /></font></div>
<div>
<blockquote type="cite" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #1abc9c;">
<div class="pre" style="margin: 0px; padding: 0px; font-family: monospace;">mat[:,0]=vect0[:,0]</div>
</blockquote>
</div>
<div><font face="monospace"><br /></font></div>
<div><font face="Helvetica">mat[:,0] seems to have shape of (5,) which is just length-5 array, so setting it equal to 1xN or Nx1 arrays seems to cause some issues.</font></div>
<div><font face="Helvetica"><br /></font></div>
</div>
<div name="messageSignatureSection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;"><br />
- Brian</div>
<div name="messageReplySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;"><br />
On Jul 3, 2017, 15:57 -0400, paul.carrico@free.fr, wrote:<br />
<blockquote type="cite" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #1abc9c;">
<div class="pre" style="margin: 0; padding: 0; font-family: monospace">Dear All</div>
<div class="pre" style="margin: 0; padding: 0; font-family: monospace"> </div>
<div class="pre" style="margin: 0; padding: 0; font-family: monospace">I'm a like matlab user (more specifically a Scilab one) for years, and because I've to deal with huge ascii files (with dozens of millions of lines), I decided to have a look to Python and Numpy, including vectorization topics.</div>
<div class="pre" style="margin: 0; padding: 0; font-family: monospace"> </div>
<div class="pre" style="margin: 0; padding: 0; font-family: monospace">Obviously I've been influenced by my current feedbacks.</div>
<div class="pre" style="margin: 0; padding: 0; font-family: monospace"> </div>
<div class="pre" style="margin: 0; padding: 0; font-family: monospace">I've a basic question concerning the current code: why it is necessary to transpose the column vector (still in the right format in my mind)? does it make sens?</div>
<div class="pre" style="margin: 0; padding: 0; font-family: monospace"> </div>
<div class="pre" style="margin: 0; padding: 0; font-family: monospace">Thanks</div>
<div class="pre" style="margin: 0; padding: 0; font-family: monospace"> </div>
<div class="pre" style="margin: 0; padding: 0; font-family: monospace">Paul</div>
<div class="pre" style="margin: 0; padding: 0; font-family: monospace"> </div>
<div class="pre" style="margin: 0; padding: 0; font-family: monospace">####################################</div>
<div class="pre" style="margin: 0; padding: 0; font-family: monospace">import numpy as np ## np = raccourci<br />
<br />
## works with a row vector<br />
vect0 = np.random.rand(5); print vect0; print("\n")<br />
mat = np.zeros((5,4),dtype=float)<br />
mat[:,0]=np.transpose(vect0); print mat<br />
<br />
## works while the vector is still in column i.e. in a right format, isn't it?<br />
vect0 = np.random.rand(5,1); print vect0; print("\n")<br />
mat = np.zeros((5,4),dtype=float)<br />
mat[:,0]=np.transpose(vect0); print mat<br />
<br />
## does not work<br />
vect0 = np.random.rand(5,1); print vect0; print("\n")<br />
mat = np.zeros((5,4),dtype=float)<br />
mat[:,0]=np(vect0); print mat</div>
_______________________________________________<br />
NumPy-Discussion mailing list<br />
NumPy-Discussion@python.org<br />
https://mail.python.org/mailman/listinfo/numpy-discussion<br /></blockquote>
</div>
</body>
</html>