Hi all,
I've had some trouble getting the numarray-1.3.1 setup scripts to
recognize the optimized BLAS/LAPACK, veclib, on OS X. But I think I've
tracked down the problems.
First, the section of addons.py that checks for the existence of the
framework (around line 47) needs to set lapack_dirs = [], I think,
since it needs to exist later on.
Second, the section after that that sets lapack_compile_args,
lapack_link_args and lapack_include_dirs for *all* cases (lines 57-60)
overwrites lapack_link_args from the if...elif...else above.
Finally, cblas.h isn't included correctly, since the framework option
is only used for linking, not compiling.
I've attached a patchfile for addons.py below; I switched the two
sections and added to the framework if... clause. Use it with
> patch addons.py addons.patch
I hope this is a reasonable way to propagate this to the developers.
Please let me know if it doesn't work for any reason, or if it breaks
any other install, which I haven't checked. I assume it works on my
machine, since:
> otool -L
build/lib.darwin-7.9.0-Power_Macintosh-2.3/numarray/linear_algebra/
lapack_lite2.so
/System/Library/Frameworks/Python.framework/Versions/2.3/Python
(compatibility version 2.3.0, current version 2.3.0)
/System/Library/Frameworks/vecLib.framework/Versions/A/vecLib
(compatibility version 1.0.0, current version 153.2.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0,
current version 71.1.3)
Andrew
p.s. only tested under OS X 10.3.9 (latest version of Panther).
______________________________________________________________________
Andrew Jaffe a.jaffe(a)imperial.ac.uk
Astrophysics Group +44 207 594-7526
Blackett Laboratory, Room 1013 FAX 7541
Imperial College, Prince Consort Road
London SW7 2AZ ENGLAND http://astro.imperial.ac.uk/~jaffe

Hi
I have a large 1D numarray array with some huge values and lots of
zeros. Now, for better representation I wanted to plot the logarithm.
Well, calculating the logarithm is not such a good idea if you have
zeros in your array ...
However, how do you implement such cases like "only apply a function if
a certain condition is true", I'd like to ask whether there are nice
short snippets which could show such cases. My own code is
(unnecessarily?) long and ugly. I tried to combine 'where' and
'greater', but didn't succeed. I guess I'm just don't see the wood for
the trees. How would you write this in my case?
TIA
Regards,
Christian

I am running under python 1.4 and windows XP.
I get the following results in my python interpretter:
--------------------------------------------
n=0
import RandomArray
while 1:
arr = RandomArray.randint(0, 2509, 252)
for x in arr:
if x>2508:
raise "Found number greater than 2508: " +
str(x) + " on iteration " + str(n)
n=n+1
Traceback (most recent call last):
File "<pyshell#43>", line 5, in -toplevel-
raise "Found number greater than 2508: " + str(x) + " on iteration
" + str(n)
Found number greater than 2508: 2509 on iteration 91719
-------------------------------------------
Even though the Numeric reference (see below) on RandomArray class
claims that the number returned is always strictly less than the max.
Does anyone
know what might cause this problem?
randint(minimum, maximum, shape=ReturnFloat)
The randint() function returns an array of the specified shape and
containing random (standard) integers greater than or equal to minimum
and strictly less than maximum . If no shape is specified, a single
number is returned. (exerpt from
http://www.pfdubois.com/numpy/html2/numpy-19.html#pgfId-303108)

I have up-to-date (5/18/05) Debian unstable on a PC. I compiled Python
and numarray from source and I keep them in "/usr/local". Python is
version 2.4.1 and numarray is version 1.3.1. The output of the program
below is:
0.0 1.0
-0.107813523267 1.10781352327
I would expect a rotated image to have min == 0.0 and max == 1.0. The
max and min of arr2 occur near the edge of the rotated half plane. This
looks like a bug in nd_image.
-------------------------
#! /usr/bin/env python
import numarray, numarray.nd_image
arr = numarray.zeros((256, 256), 'Float64')
arr[128:, :] = 1.0
print arr.min(), arr.max()
arr2 = numarray.nd_image.rotate(arr, 30, reshape=False)
print arr2.min(), arr2.max()

On Wed, 2005-05-18 at 12:58, Carlos Pita wrote:
> > > The documentation for PyArray_FromDimsAndData
> > > that I quoted in my previous post seems to suggest
> > > that a copy is done. But browsing the web
> >
> > I'd appreciate it if you could send me a reference to where that is
> > because it is stale.
>
> I take the excerpt from the numarray user manual from
> the python2.3-numarray 1.1.1 debian (sarge) package.
> But it's updated in the cvs:
>
> \begin{cfuncdesc}{PyObject*}{PyArray_FromDimsAndData}{int nd, int *dims, int type, char *data}
> This function will allocate a numarray of the specified shape and type
> which will refer to the data buffer specified by \var{data}. The contents
> of \var{data} will not be copied nor will \var{data} be deallocated upon
> the deletion of the array.
> \end{cfuncdesc}
>
> It seems to be ok. When it says "nor will \var{data} be deallocated upon
> the deletion of the array", does it mean that the python buffer object
> ref count won't be decremented ? Or, more generally, the created
> numarray will refer directly to the C array segments exposed by the
> python buffer object or will keep a reference to this object?
It means the internal buffer object refers to but does not "own" the
array data passed into PyArray_FromDimsAndData(). At deallocation
time, the internal buffer object is DECREF'd and disappears but the
storage referred to by the data parameter does not. So, I/O buffers or
other statically allocated arrays should work.
Regards,
Todd

Hi!
I need to wrap a pre-existent C array into
a numarray. It shouldn't be a copy of the
original array because this is an audio buffer
with a fixed address and also input/output
copying from/to the buffer would be overkilling,
so the numarray *must* be lightly wrapping the
buffer and not a memcpy of it. But NA_NewArray
duplicates the passed buffer so I'm not sure
how to achieve the goal stated above or if
it's possible at all.
Can you help me?
Regards,
Carlos

Hello NG,
I am not really a guru with Numeric, and I am trying to port some Matlab
code to Python, using Numeric. The code is working, but it is slown down
because of the different implementation (ordering) of reshape() in Matlab
and Numeric.
For example, in Matlab I can do:
a = 1:10;
reshape(a,5,2)
ans =
1 6
2 7
3 8
4 9
5 10
In Numeric:
a = range(1, 11)
Numeric.reshape(a, (5,2))
array([[ 1, 2],
[ 3, 4],
[ 5, 6],
[ 7, 8],
[ 9, 10]])
Hmm... let's try again...
Numeric.reshape(a, (2,5))
array([[ 1, 2, 3, 4, 5],
[ 6, 7, 8, 9, 10]])
Hmm... the only solution I found:
Numeric.transpose(Numeric.reshape(a, (2,5)))
array([[ 1, 6],
[ 2, 7],
[ 3, 8],
[ 4, 9],
[ 5, 10]])
This continuous use of transpose() is killing the performances of my scripts...
is there a workaround? Am I missing something so obvious?
Thank you for every suggestion.
Andrea.

Hello NG,
in one script, I generated a matrix "dx" which has a (200000, 10) shape.
Well, everything is working fine (matrix multiplication, sum, exponentiation
etc...), but I'm having problems in squaring all elements of this matrix.
Suppose I have:
import Numeric
import random
dx = Numeric.ones((200000,10), Numeric.Float0, savespace=1)
dx[:,:] = random.random()
td1 = dx*2.0 ---> This takes about 0.2 seconds
td2 = dx**2.0 ---> This takes about 6 seconds
Why this difference? And why it is so slow the exponentiation? I have tried
the same operation in Matlab and it was almost instantaneous. I don't want
to stick with Matlab, noting the great job the Numeric developers have done.
Is there something that I am missing?
Sorry if it is a basic question.
Andrea.

Hi,
Is this really obvious to everybody:
>>> type(a)
<class 'numarray.numarraycore.NumArray'>
>>> a.shape
(12, 13, 2, 5)
>>> a[(0,0)].shape
(2, 5)
>>> a[[0,0]].shape
(2, 13, 2, 5)
>>> na.take(a,[0,0]).shape
(2, 13, 2, 5)
Is there some explanation in the documentation ? (Is this the same in
Numeric / Numeric3 ?)
Thanks,
Sebastian Haase