Nonzero

Return the n-dimensional indices for elements of the n-dimensional array self that are nonzero into an n-tuple of equal-length index arrays. In particular, notice that a 0-dimensional array always returns an empty tuple.

>>> x = arange(15);

y=x.reshape(3,5)

>>> (x>8),nonzero()

(array([ 9, 10, 11,

12, 13,

14] ) , )

>>> (y>8).nonzero()

(array([1, 2, 2, 2,

2, 2] ) ,

array([4, 0, 1, 2, 3, 4]))

compress (condition=, axis=None, out=None)

This method expects condition to be a one-dimensional mask array of the same length as self.shape[axis]. If the array is less than self.shape[axis], then False is assumed for the missing elements. The method returns the elements (or sub-arrays along the given axis) of self where condition is true. The shape of the return array is self.shape with the axis dimension replaced by the number of True elements of condition. The same effect can often be accomplished using array indexing.

>>> x=array([0,1,2,3]) >>> x.compress(x > 2) array([3]) >>> x[x>2] array([3])

diagonal (offset=0, axis1=0, axis2=1)

If self is 2-d, return the offset (from the main diagonal) diagonal of self. If self is larger than 2-d, then return an array constructed from all the diagonals created from all the 2-d sub-arrays formed using all of axis1 and axis2. The offset parameter is with respect to axis2. The shape of the returned array is found by removing the axis1 and axis2 entries from self.shape and then appending the length of the offset diagonal of each 2-d sub-array.

3.2.4 Array calculation

Many of these methods take an argument named axis. In such cases, if axis is None (the default), the array is treated as a 1-d array and the operation is performed over the entire array. This behavior is also the default if self is a 0-dimensional array or array scalar. If axis is an integer, then the operation is done over the given axis (for each 1-d subarray that can be created along the given axis). The parameter dtype specifies the data type over which a reduction operation (like summing) should take place. The default reduce data type is the same as the data type of self. To avoid overflow, it can be useful to perform the reduction using a larger data type. For several methods, an optional out argument can be provided and the result will be placed into the output array given. The out argument must be an ndarray and have the same number of elements. It can be of a different type in which case casting will be performed.

max (axis=None, out=None)

Table 3.3: Array item selection and shape manipulation methods. If axis is an argument, then the calculation is performed along that axis. An axis value of None means the array is flattened before calculation proceeds.

Method

Arguments

Description

argsort

argsort (axis=None, kind='quick')

Indices showing how to sort array.

choose

choose (cO, cl , ..., cn, out=None, clip='raise')

Choose from different arrays based on value of self.

compress

(condition=, axis=None, out=None)

Elements of self where condition is true.

diagonal

(offset=0, axisl=0, axis2=l)

Return a diagonal from self.

flatten

(order='C)

A 1-d copy of self.

nonzero

0

True where self is not zero.

put

(indices=, values=, mode='raise')

Place values at 1-d index locations of self.

ravel

(order='C)

1-d version of self (no data copy if self is C-style contiguous).

repeat

(repeats=, axis=None)

Repeat elements of self.

reshape

(dl,d2,...,dn, order='C)

Return reshaped version of self.

resize

(dl,d2,...,dn, refcheck=l, order='Any')

Resize self in-place.

searchsorted

(values)

Show where values would be placed in self (assumed sorted).

sort

(axis=None, kind='quick')

Copy of self sorted along axis.

squeeze

0

Squeeze out all length-1 dimensions.

swapaxes

(axisl, axis2)

Swap two dimensions of self.

take

(indices=, axis=None, out=None, mode='raise')

Select elements of self along axis according to indices.

transpose

(permute <None>)

Rearrange shape of self according to permute.

Return the largest value in self. This is a better way to compute the maximum over an array, than using max(self). The latter uses the generic sequence interface to self. This will be slower, and will try to get an answer by comparing whole sub-arrays of self. This will be incorrect for arrays larger than 1-d.

argmax (axis=None, out=None)

Return the (first, 1-d) index of the largest value in self. min (axis=None, out=None)

Return the smallest value in self. This is a better way to compute the minimum over an array, than using min(self). The latter uses the generic sequence interface to self. This will be slower, and will try to get an answer by comparing whole sub-arrays of self. This will be incorrect for arrays larger than 1-d.

argmin (axis=None, out=None)

Return the (first, 1-d) index of the smallest value in self. ptp (axis=None, out=None)

Return the difference of the largest to the smallest value in self. Equivalent to self.max(axis) - self.min(axis)

Return a new array where any element in self less than min is set to min and any element less than max is set to max. Equivalent to self[self<min]=min; self[self>max]=max.

conj (out=None)

conjugate (out=None)

Return the conjugate of elements of the array. round (decimals=0, out=None)

Round the elements of the array to the nearest decimal. For decimals < 0, the rounding is done to the nearest tens, hundreds, etc. Rounding of exactly the half-interval is to the nearest even integer. This is the only difference with standard Python rounding.

trace (offset=0, axis1=0, axis2=1, dtype=None, out=None)

Perform a summation along each diagonal specified by offset, axisl, and axis2. Equivalent to diagonal(offset,axis1,axis2).sum(axis=-1, dtype=dtype)

sum (axis=None, dtype=None, out=None) Return the sum

axis where axis objects are placed before the i.

cumsum (axis=None, dtype=None, out=None)

Return the cumulative sum. If ret is the return array of the same shape as self, then

mean (axis=None, dtype=None, out=None) Return the average value caculated as

where N is self.shape[axis] and axis objects are placed before the i. The sum is done in the data-type of self unless self is an integer or Boolean data-type and then it is done over the float data-type.

var (axis=None, dtype=None, out=None) Return the variance of the data calculated as

^ ^ \ axis where N is self.shape[axis] and ^ is the mean (restored to the same number of dimensions as self with ^ copied along the axis dimension). This is equivalent to (self**2).mean - self.mean()**2 and ((self-self.mean())**2).mean(). The value of N — 1 was not chosen for normalization because while it gives an "unbiased" estimate, it is not always prudent to return unbiased estimates as they may have larger mean-square error. The sum is done using a float data-type if self has integer or Boolean data-type, otherwise it is done using the same data-type as self.

std (axis=None, dtype=None, out=None)

Return the standard deviation calculated as

- I i] - At i 0 \ axis where N is self.shape[axis] and ^ is the mean (restored to the same number of dimensions as self with ^ copied along the axis dimension). The sum is done using the same data-type as self unless self is an integer or Boolean data-type and then it is done using a float data-type.

prod (axis=None, dtype=None, out=None)

Return the product calculated as

cumprod (axis=None, dtype=None, out=None)

Return the cumulative product so that the return array, ret, is the same shape as self and retl^^., j] = Ij i].

Return True if all entries along axis evaluate True, otherwise return False. any (axis=None, out=None) Return True if any entries along axis evaluate True, otherwise return False.

Table 3.4: Array object calculation methods. If axis is an argument, then the calculation is performed along that axis. An axis value of None means the array is flattened before calculation proceeds. All of these methods can take an optional out= argument which can specify the output array to write the results into.

Table 3.4: Array object calculation methods. If axis is an argument, then the calculation is performed along that axis. An axis value of None means the array is flattened before calculation proceeds. All of these methods can take an optional out= argument which can specify the output array to write the results into.

Method

Arguments

Description

all

(a,xis=None)

true if all entries are true.

any

(axis=None)

true if any entries are true.

argmax

(axis=None)

index of largest value.

argmin

(axis=None)

index of smallest value.

clip

(min=, max=)

self[self>max]=max; self[self<min]=min

conj

0

complex conjugate

cumprod

(axis=None, dtype=None)

cumulative product

cumsum

(axis=None, dtype=None)

cumulative sum

max

(axis=None)

maximum of self

mean

(axis=None, dtype=None)

mean of self

min

(axis=None)

minimum of self

prod

(axis=None, dtype=None)

multiply elements of self together

ptp

(axis=None)

self .max( axis)-self .min (axis)

var

(axis=None, dtype=None)

variance of self

std

(axis=None, dtype=None)

standard deviation of self

sum

(axis=None, dtype=None)

add elements of self together

trace

(offset, axis 1=0, axis2=0, dtype=None)

sum along a diagonal

0 0

Post a comment