# [Numpy-discussion] fast access and normalizing of ndarray slices

Wolfgang Kerzendorf wkerzendorf at gmail.com
Thu May 31 09:27:16 EDT 2012

```Hey Val,

Well it doesn't matter what I do, but specifically I do factor = sum(data_array[start_point:start_point+length_data]) and then
data[array[start_point:start_point+length_data]) /= factor. and that for every star_point and length data.

How to do this fast?

Cheers
Wolfgang
On 2012-05-31, at 1:43 AM, Val Kalatsky wrote:

> What do you mean by "normalized it"?
> Could you give the output of your procedure for the sample input data.
> Val
>
> On Thu, May 31, 2012 at 12:36 AM, Wolfgang Kerzendorf <wkerzendorf at gmail.com> wrote:
> Dear all,
>
> I have an ndarray which consists of many arrays stacked behind each other (only conceptually, in truth it's a normal 1d float64 array).
> I have a second array which tells me the start of the individual data sets in the 1d float64 array and another one which tells me the length.
> Example:
>
> data_array = (conceptually) [[1,2], [1,2,3,4], [1,2,3]] = in reality [1,2,1,2,3,4,1,2,3, dtype=float64]
> start_pointer = [0, 2, 6]
> length_data = [2, 4, 3]
>
> I now want to normalize each of the individual data sets. I wrote a simple for loop over the start_pointer and length data grabbed the data and normalized it and wrote it back to the big array. That's slow. Is there an elegant numpy way to do that? Do I have to go the cython way?
>
> Cheers
>   Wolfgang
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20120531/30fa80a1/attachment.html>
```