Language:EN
Pages: 2
Rating : ⭐⭐⭐⭐⭐
Price: $10.99
Page 1 Preview
the return shape has dimensions python code many o

The return shape has dimensions python code many other uses

and cumprod methods of arrays. The following Python code implements an

equivalent of the accumulate method.

This method is a generalization of both reduce and accumulate. It offers the

ability to reduce along an axis but only between certain indices. The indices input must be a one dimensional (index) sequence. Then, if Ik is the kthele-ment of indices, the reduceat method computes <op>.reduce(array[Ik:Ik+1]).

Equivalent Python code is� �� �

>>> i1 = [index exp[:]]*array.ndim
>>> i2 = [index exp[:]]*array.ndim
>>> outshape = list(array.shape)
>>> N = array.shape[axis]
>>> outshape[axis] = len(indices)
>>> result = zeros(outshape, dtype or array.dtype) >>> for k,Ik in enumerate(indices):
i1[axis] = k ...

Example: Suppose a is a two-dimensional array of shape 10 × 20. Then, res=add.reduce (a, [0,3,1]) returns a 3 × 20 array with res[0,:] = add.reduce(a[:,0:3]), res[1,:] = a[:,3], and res[2,:] = add.reduce(a[:,1:]).

9.4.4 Outer

Among many other uses, arithmetic tables can be conveniently built using outer:

>>> multiply.outer([1,7,9,12],arange(5,12))

array([[ 5, 6,
10,
[ 35,

42,

49,

56, 63, 70, 77],
[ 45,
72, 81, 90, 99],
[ 60,
96, 108, 120, 132]])

166

You are viewing 1/3rd of the document.Purchase the document to get full access instantly

Immediately available after payment
Both online and downloadable
No strings attached
How It Works
Login account
Login Your Account
Place in cart
Add to Cart
send in the money
Make payment
Document download
Download File
img

Uploaded by : Lawrence Frazier

PageId: ELIFB2287B