Miscellaneous routines (scipy.misc)

Warning

This documentation is work-in-progress and unorganized.

Various utilities that don’t have another home.

scipy.misc.who(vardict=None)

Print the Numpy arrays in the given dictionary.

If there is no dictionary passed in or vardict is None then returns Numpy arrays in the globals() dictionary (all Numpy arrays in the namespace).

Parameters:

vardict : dict, optional

A dictionary possibly containing ndarrays. Default is globals().

Returns:

out : None

Returns ‘None’.

Notes

Prints out the name, shape, bytes and type of all of the ndarrays present in vardict.

Examples

>>> d = {'x': arange(2.0), 'y': arange(3.0), 'txt': 'Some str', 'idx': 5}
>>> np.whos(d)
Name            Shape            Bytes            Type
===========================================================
<BLANKLINE>
y               3                24               float64
x               2                16               float64
<BLANKLINE>
Upper bound on total bytes  =       40
scipy.misc.source(object, output=<open file '<stdout>', mode 'w' at 0x2aaaaaac9198>)

Print or write to a file the source code for a Numpy object.

Parameters:

object : numpy object

Input object.

output : file object, optional

If output not supplied then source code is printed to screen (sys.stdout). File object must be created with either write ‘w’ or append ‘a’ modes.

scipy.misc.info(object=None, maxwidth=76, output=<open file '<stdout>', mode 'w' at 0x2aaaaaac9198>, toplevel='scipy')

Get help information for a function, class, or module.

Parameters:

object : optional

Input object to get information about.

maxwidth : int, optional

Printing width.

output : file like object open for writing, optional

Write into file like object.

toplevel : string, optional

Start search at this level.

Examples

>>> np.info(np.polyval) # doctest: +SKIP

polyval(p, x)

Evaluate the polymnomial p at x.

...

scipy.misc.fromimage(im, flatten=0)

Return a copy of a PIL image as a numpy array.

Parameters:
im : PIL image

Input image.

flatten : bool

If true, convert the output to grey-scale.

Returns:
img_array : ndarray

The different colour bands/channels are stored in the third dimension, such that a grey-image is MxN, an RGB-image MxNx3 and an RGBA-image MxNx4.

scipy.misc.toimage(arr, high=255, low=0, cmin=None, cmax=None, pal=None, mode=None, channel_axis=None)

Takes a numpy array and returns a PIL image. The mode of the PIL image depends on the array shape, the pal keyword, and the mode keyword.

For 2-D arrays, if pal is a valid (N,3) byte-array giving the RGB values (from 0 to 255) then mode=’P’, otherwise mode=’L’, unless mode is given as ‘F’ or ‘I’ in which case a float and/or integer array is made

For 3-D arrays, the channel_axis argument tells which dimension of the
array holds the channel data.
For 3-D arrays if one of the dimensions is 3, the mode is ‘RGB’
by default or ‘YCbCr’ if selected.

if the

The numpy array must be either 2 dimensional or 3 dimensional.

scipy.misc.imsave(name, arr)
Save an array to an image file.
scipy.misc.imread(name, flatten=0)

Read an image file from a filename.

Optional arguments:

  • flatten (0): if true, the image is flattened by calling convert(‘F’) on

the resulting image object. This flattens the color layers into a single grayscale layer.

scipy.misc.imrotate(arr, angle, interp='bilinear')

Rotate an image counter-clockwise by angle degrees.

Interpolation methods can be:
‘nearest’ : for nearest neighbor ‘bilinear’ : for bilinear ‘cubic’ or ‘bicubic’ : for bicubic
scipy.misc.imresize(arr, size)

Resize an image.

If size is an integer it is a percentage of current size. If size is a float it is a fraction of current size. If size is a tuple it is the size of the output image.

scipy.misc.imshow(arr)
Simple showing of an image through an external viewer.
scipy.misc.imfilter(arr, ftype)

Simple filtering of an image.

type can be:
‘blur’, ‘contour’, ‘detail’, ‘edge_enhance’, ‘edge_enhance_more’, ‘emboss’, ‘find_edges’, ‘smooth’, ‘smooth_more’, ‘sharpen’
scipy.misc.factorial(n, exact=0)

n! = special.gamma(n+1)

If exact==0, then floating point precision is used, otherwise exact long integer is computed.

Notes:
  • Array argument accepted only for exact=0 case.
  • If n<0, the return value is 0.
scipy.misc.factorial2(n, exact=0)
n!! = special.gamma(n/2+1)*2**((m+1)/2)/sqrt(pi) n odd
= 2**(n) * n! n even

If exact==0, then floating point precision is used, otherwise exact long integer is computed.

Notes:
  • Array argument accepted only for exact=0 case.
  • If n<0, the return value is 0.
scipy.misc.factorialk(n, k, exact=1)
n(!!...!) = multifactorial of order k k times
scipy.misc.comb(N, k, exact=0)

Combinations of N things taken k at a time.

If exact==0, then floating point precision is used, otherwise exact long integer is computed.

Notes:
  • Array arguments accepted only for exact=0 case.
  • If k > N, N < 0, or k < 0, then a 0 is returned.
scipy.misc.central_diff_weights(Np, ndiv=1)

Return weights for an Np-point central derivative of order ndiv assuming equally-spaced function points.

If weights are in the vector w, then derivative is w[0] * f(x-ho*dx) + ... + w[-1] * f(x+h0*dx)

Can be inaccurate for large number of points.

scipy.misc.derivative(func, x0, dx=1.0, n=1, args=(), order=3)

Given a function, use a central difference formula with spacing dx to compute the nth derivative at x0.

order is the number of points to use and must be odd.

Warning: Decreasing the step size too small can result in round-off error.

scipy.misc.pade(an, m)
Given Taylor series coefficients in an, return a Pade approximation to the function as the ratio of two polynomials p / q where the order of q is m.