Is it possible to calculate a dot product in numpy by either notation
(a ^ b, where ^ is a possible notation) or calling a dot function
(dot(a,b)? I'm trying to use a column matrix for both "vectors".
Perhaps, I need to somehow change them to arrays?
--
Wayne Watson (Watson Adventures, Prop., Nevada City, CA)
(121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet
"... humans'innate skills with numbers isn't much
better than that of rats and dolphins."
-- Stanislas Dehaene, neurosurgeon
Web Page: <www.speckledwithstars.net/>

Hi,
Following on from the occasional discussion on the list, can I propose
a small matrix_rank function for inclusion in numpy/linalg?
I suggest it because it seems rather a basic need for linear algebra,
and it's very small and simple...
I've appended an implementation with some doctests in the hope that it
will be acceptable,
Robert - I hope you don't mind me quoting you in the notes.
Thanks a lot,
Matthew
def matrix_rank(M, tol=None):
''' Return rank of matrix using SVD method
Rank of the array is the number of SVD singular values of the
array that are greater than `tol`.
Parameters
----------
M : array-like
array of <=2 dimensions
tol : {None, float}
threshold below which SVD values are considered zero. If `tol`
is None, and `S` is an array with singular values for `M`, and
`eps` is the epsilon value for datatype of `S`, then `tol` set
to ``S.max() * eps``.
Examples
--------
>>> matrix_rank(np.eye(4)) # Full rank matrix
4
>>> matrix_rank(np.c_[np.eye(4),np.eye(4)]) # Rank deficient matrix
4
>>> matrix_rank(np.zeros((4,4))) # All zeros - zero rank
0
>>> matrix_rank(np.ones((4,))) # 1 dimension - rank 1 unless all 0
1
>>> matrix_rank(np.zeros((4,)))
0
>>> matrix_rank([1]) # accepts array-like
1
Notes
-----
Golub and van Loan define "numerical rank deficiency" as using
tol=eps*S[0] (note that S[0] is the maximum singular value and thus
the 2-norm of the matrix). There really is not one definition, much
like there isn't a single definition of the norm of a matrix. For
example, if your data come from uncertain measurements with
uncertainties greater than floating point epsilon, choosing a
tolerance of about the uncertainty is probably a better idea (the
tolerance may be absolute if the uncertainties are absolute rather
than relative, even). When floating point roundoff is your concern,
then "numerical rank deficiency" is a better concept, but exactly
what the relevant measure of the tolerance is depends on the
operations you intend to do with your matrix. [RK, numpy mailing
list]
References
----------
Matrix Computations by Golub and van Loan
'''
M = np.asarray(M)
if M.ndim > 2:
raise TypeError('array should have 2 or fewer dimensions')
if M.ndim < 2:
return int(not np.all(M==0))
S = npl.svd(M, compute_uv=False)
if tol is None:
tol = S.max() * np.finfo(S.dtype).eps
return np.sum(S > tol)

===========================
Announcing PyTables 2.2b2
===========================
PyTables is a library for managing hierarchical datasets and designed to
efficiently cope with extremely large amounts of data with support for
full 64-bit file addressing. PyTables runs on top of the HDF5 library
and NumPy package for achieving maximum throughput and convenient use.
This is the second beta version of 2.2 release. The main addition is
the support for links. All HDF5 kind of links are supported: hard, soft
and external. Hard and soft links are similar to hard and symbolic
links in regular UNIX filesystems, while external links are more like
mounting external filesystems (in this case, HDF5 files) on top of
existing ones. This allows for a considerable degree of flexibility
when defining your object tree. See the new tutorial at:
http://www.pytables.org/docs/manual-2.2b2/ch03.html#LinksTutorial
Also, some other new features (like complete control of HDF5 chunk cache
parameters and native compound types in attributes), bug fixes and a
couple of (small) API changes happened.
In case you want to know more in detail what has changed in this
version, have a look at:
http://www.pytables.org/moin/ReleaseNotes/Release_2.2b2
You can download a source package with generated PDF and HTML docs, as
well as binaries for Windows, from:
http://www.pytables.org/download/preliminary
For an on-line version of the manual, visit:
http://www.pytables.org/docs/manual-2.2b2
Resources
=========
About PyTables:
http://www.pytables.org
About the HDF5 library:
http://hdfgroup.org/HDF5/
About NumPy:
http://numpy.scipy.org/
Acknowledgments
===============
Thanks to many users who provided feature improvements, patches, bug
reports, support and suggestions. See the ``THANKS`` file in the
distribution package for a (incomplete) list of contributors. Most
specially, a lot of kudos go to the HDF5 and NumPy (and numarray!)
makers. Without them, PyTables simply would not exist.
Share your experience
=====================
Let us know of any bugs, suggestions, gripes, kudos, etc. you may
have.
----
**Enjoy data!**
-- The PyTables Team
--
Francesc Alted

In this code,
===========start
import math
import numpy as np
from numpy import matrix
def sinD(D): # given in degrees, convert to radians
return sin(radians(D))
def cosD(D):
return cos(radians(D)) <<--------------
def acosD(D):
acos(radians(D))
return=====end
the << line produces, "NameError: global name 'cos' is not defined", but
the sin() above it does not? They are both built-in functions.
--
Wayne Watson (Watson Adventures, Prop., Nevada City, CA)
(121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet
"... humans'innate skills with numbers isn't much
better than that of rats and dolphins."
-- Stanislas Dehaene, neurosurgeon
Web Page: <www.speckledwithstars.net/>

I am building Numpy on OSX 10.6 using a recent update
from SVN (r7726). Though I was able to build the package
successfully, the resulting package generates an ImportError:
import umath
ImportError: dlopen(/Library/Python/2.6/site-packages/
numpy-1.4.0.dev7726-py2.6-macosx-10.6-
universal.egg/numpy/core/umath.so, 2): Symbol not found
: _npy_cexp
Referenced from: /Library/Python/2.6/site-packages/
numpy-1.4.0.dev7726-py2.6-macosx-10.6-universal.egg/
numpy/core/umath.so
Expected in: flat namespace
in /Library/Python/2.6/site-packages/
numpy-1.4.0.dev7726-py2.6-macosx-10.6-universal.egg
/numpy/core/umath.so
Note that this did not occur previously (r7542). For some reason
umath is not being built properly.

Hi everyone,
I was wondering if anyone had insight on the best way to solve the
following problem.
Suppose I have a numpy array called U.
U has shape (N,M)
Suppose further that I have another array called dU and that
dU has shape (P,M) and that P has no particular relationship to N, it
could be larger or smaller.
Additionally, I have a one dimensional array called idx and
idx has shape (P,). Furthermore idx holds integers that are all valid
indices into the rows of U. idx almost certainly contains some
duplicates.
I want,
for k in range(P):
U[idx[k],:] += dU[k,:]
Is there a nice vectorized and efficient way to do this without making
the obvious python for loop I included above? For what I am doing, P
is usually quite large. I am most interested in a clever use of
numpy/scipy commands and Python and not Cython.
Thanks in advance for any suggestions.
- George

Hello,
Here are the steps that I went through to install the numpy from the
svn-repo:
svn co http://svn.scipy.org/svn/numpy/trunk numpy
Be "su" and type: python setupegg.py develop
Successful installation so far, but import fails with the given error:
[gsever@ccn Desktop]$ python
Python 2.6 (r26:66714, Jun 8 2009, 16:07:26)
[GCC 4.4.0 20090506 (Red Hat 4.4.0-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/gsever/Desktop/python-repo/numpy/numpy/__init__.py", line 132,
in <module>
import add_newdocs
File "/home/gsever/Desktop/python-repo/numpy/numpy/add_newdocs.py", line
9, in <module>
from numpy.lib import add_newdoc
File "/home/gsever/Desktop/python-repo/numpy/numpy/lib/__init__.py", line
4, in <module>
from type_check import *
File "/home/gsever/Desktop/python-repo/numpy/numpy/lib/type_check.py",
line 8, in <module>
import numpy.core.numeric as _nx
File "/home/gsever/Desktop/python-repo/numpy/numpy/core/__init__.py", line
6, in <module>
import umath
ImportError: /home/gsever/Desktop/python-repo/numpy/numpy/core/umath.so:
undefined symbol: npy_spacing
My platform:
Linux-2.6.29.6-217.2.3.fc11.i686.PAE-i686-with-fedora-11-Leonidas
Any ideas what might be wrong here?
--
Gökhan

I've just become acquainted with the help command in WinXP IDLE.
help(numyp.sin) works fine. What's going on with dot?
>>> help(numpy.core.multiarray.dot)
Help on built-in function dot in module numpy.core.multiarray:
dot(...)
Is there help for dot?
--
Wayne Watson (Watson Adventures, Prop., Nevada City, CA)
(121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet
"... humans'innate skills with numbers isn't much
better than that of rats and dolphins."
-- Stanislas Dehaene, neurosurgeon
Web Page: <www.speckledwithstars.net/>