473,395 Members | 1,595 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

[numarray] mean vector of 2d matrix

Hi all,

I was wondering what is the best way to compute the mean vector of a
matrix. Currently I'm doing this:
data.shape (117027, 8) mean = (numarray.add.reduce(data, axis=1))/(data.shape[1])


but maybe there is a faster way?

cheers
Jul 18 '05 #1
2 2316
Curzio Basso <cu**********@unibas.ch> wrote in message news:<40********@maser.urz.unibas.ch>...
Hi all,

I was wondering what is the best way to compute the mean vector of a
matrix. Currently I'm doing this:


With Numeric, one can use the 'average' function to compute the average along
an axis, or the average of all elements when the axis argument is set to None.
See p317 of Martelli's "Python in a Nutshell" book. For example, the code

from Numeric import zeros,Float,average
nr = 3
nc = 2
xx = zeros([nr,nc],Float)
for i in range(nr):
for j in range(nc):
xx[i,j] = i + 10.0*j
print xx
for i in [None,0,1]: print "\n",i,average(xx,axis=i)

produces output

[[ 0. 10.]
[ 1. 11.]
[ 2. 12.]]

None 6.0

0 [ 1. 11.]

1 [ 5. 6. 7.]
Jul 18 '05 #2
be*******@aol.com wrote:
With Numeric, one can use the 'average' function to compute the average along
an axis, or the average of all elements when the axis argument is set to None.
See p317 of Martelli's "Python in a Nutshell" book. For example, the code


However, it looks like in numarray no average() is provided. Now I found
out there is an average() function provided by the MA (Masked Arrays)
module, but I do not really understand why there is an average()
function for a masked array and not for a generic array...

Anyway, thanks for the tip!
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Colin J. Williams | last post by:
numarray is a package which is under development and intended to replace Numeric, an efficient and operational package. One of the classes in numarray is NumArray. As currently implemented,...
4
by: Marco Bubke | last post by:
Hi Ok, I get a reproduceable seqmentation fault. Ok, fist the code: cdef NumArray array_to_double(NumArray array): # maybe here is memoty leak! cdef NumArray flat_array_obj flat_array_obj...
4
by: Christian Seberino | last post by:
How add a column to a 2d array/matrix in numarray??? The unelegant way I found was to: 1. Create a new array with an extra column (e.g. using 'zeros' function). 2. Copy original array into new...
4
by: Christopher T King | last post by:
In a quest to speed up numarray computations, I tried writing a 'threaded array' class for use on SMP systems that would distribute its workload across the processors. I hit a snag when I found out...
11
by: grv | last post by:
So it is supposed to be very fast to have an array of say 5 million integers stored in a binary file and do a = numarray.fromfile('filename', (2, 2, 2)) numarray.add(a, 9, a) but how is that...
6
by: Michael Drumheller | last post by:
(If you're not interested in NumArray, please skip this message.) I am new to NumArray and I wonder if someone can help me with array-indexing. Here's the basic situation: Given a rank-2 array...
6
by: Matt Feinstein | last post by:
Is there an optimal way to apply a function to the elements of a two-d array? What I'd like to do is define some function: def plone(x): return x+1 and then apply it elementwise to a 2-D...
22
by: J | last post by:
Hi I hope the title of this message indicates my question. I am looking for basic array functionality in Python and it turns out that there are all these packages which are somehow related....
1
by: Peterwkc | last post by:
Hello all C++ expert programmer, i fairly new to C++ programming. I have designed a matrix class which uses vector to store the data. My problem is i want store the data into vector until user...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.