[MATRIX-SIG] two newbie questions

Konrad Hinsen hinsen@ibs.ibs.fr
Fri, 8 Aug 1997 12:11:15 +0200


> 1) How much memory does an NxN Float16 matrix use?

16*N*N plus a small constant.

> 2) What's the most efficient way of constructing a "correlation-like"
>    matrix of a given function for a data set? eg. using, say, RMSE instead
>    of r?
> 
> To show you where I'm at, I'm stuck with:
> 
> def correlation_like(X, function):
>     R = zeros((len(X), len(X)), Float16)
>     for j in range(len(X)):
>         for i in range(len(X)):
>             R[i,j] = function(X[i], X[j])
>     return R

If your function can deal with arrays, it's very simple:

   R = function(X[:, Numeric.NewAxis], X)

Note that any function that uses only arithmetic and the math functions
from Numeric can deal with arrays. Example:

def function(Xi, Xj):
   return Numeric.sqrt(Xi-Xj)

(I know that this is not a particularly useful example...).
-- 
-------------------------------------------------------------------------------
Konrad Hinsen                          | E-Mail: hinsen@ibs.ibs.fr
Laboratoire de Dynamique Moleculaire   | Tel.: +33-4.76.88.99.28
Institut de Biologie Structurale       | Fax:  +33-4.76.88.54.94
41, av. des Martyrs                    | Deutsch/Esperanto/English/
38027 Grenoble Cedex 1, France         | Nederlands/Francais
-------------------------------------------------------------------------------

_______________
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________