• Facebook
  • Twitter
  • Reddit
  • StumbleUpon
  • Digg
  • email

All Samples(2536)  |  Call(2398)  |  Derive(0)  |  Import(138)
where(condition, [x, y])

Return elements, either from `x` or `y`, depending on `condition`.

If only `condition` is given, return ``condition.nonzero()``.

Parameters
----------
condition : array_like, bool
    When True, yield `x`, otherwise yield `y`.
x, y : array_like, optional
    Values from which to choose. `x` and `y` need to have the same
    shape as `condition`.

Returns
-------
out : ndarray or tuple of ndarrays
    If both `x` and `y` are specified, the output array contains
    elements of `x` where `condition` is True, and elements from
    `y` elsewhere.

    If only `condition` is given, return the tuple
    ``condition.nonzero()``, the indices where `condition` is True.

See Also
--------
nonzero, choose

Notes
-----
If `x` and `y` are given and input arrays are 1-D, `where` is
equivalent to::

    [xv if c else yv for (c,xv,yv) in zip(condition,x,y)]

Examples
--------
>>> np.where([[True, False], [True, True]],
...          [[1, 2], [3, 4]],
...          [[9, 8], [7, 6]])
array([[1, 8],
       [3, 4]])

>>> np.where([[0, 1], [1, 0]])
(array([0, 1]), array([1, 0]))

>>> x = np.arange(9.).reshape(3, 3)
>>> np.where( x > 5 )
(array([2, 2, 2]), array([0, 1, 2]))
>>> x[np.where( x > 3.0 )]               # Note: result is 1D.
array([ 4.,  5.,  6.,  7.,  8.])
>>> np.where(x < 5, x, -1)               # Note: broadcasting.
array([[ 0.,  1.,  2.],
       [ 3.,  4., -1.],
       [-1., -1., -1.]])

src/m/a/matplotlib-HEAD/py4science/examples/izhikevich_neurons.py   matplotlib(Download)
    def reset_if_action_potential(self, state):
        v, u = state
        spiked = v>=30.0
 
        if iterable(spiked):
            ind = np.nonzero(spiked)
            v = np.where(spiked, self.c, v)
            u = np.where(spiked, u + self.d, u)
 
times = np.arange(0.0, 500.0, 0.1)
V0 = -65
I = np.where(times>=100, 10, 0)
offset = 150
#ax = plt.subplot(111)
ax = plt.axes([0.125, .11, 0.725, 0.79], axisbg='w')

src/m/a/matplotlib-HEAD/toolkits/basemap/examples/ccsm_popgrid.py   matplotlib(Download)
fpin.close()
 
# make longitudes monotonically increasing.
tlon = np.where(np.greater_equal(tlon,min(tlon[:,0])),tlon-360,tlon)
 
# stack grids side-by-side (in longitiudinal direction), so
# any range of longitudes may be plotted on a world map.

src/m/a/matplotlib-HEAD/matplotlib/examples/pylab_examples/tripcolor_demo.py   matplotlib(Download)
# Mask off unwanted triangles.
xmid = x[triang.triangles].mean(axis=1)
ymid = y[triang.triangles].mean(axis=1)
mask = np.where(xmid*xmid + ymid*ymid < min_radius*min_radius, 1, 0)
triang.set_mask(mask)
 
# pcolor plot.

src/m/a/matplotlib-HEAD/matplotlib/examples/pylab_examples/tricontour_demo.py   matplotlib(Download)
# Mask off unwanted triangles.
xmid = x[triang.triangles].mean(axis=1)
ymid = y[triang.triangles].mean(axis=1)
mask = np.where(xmid*xmid + ymid*ymid < min_radius*min_radius, 1, 0)
triang.set_mask(mask)
 
# pcolor plot.

src/m/a/matplotlib-HEAD/examples/pylab_examples/tripcolor_demo.py   matplotlib(Download)
# Mask off unwanted triangles.
xmid = x[triang.triangles].mean(axis=1)
ymid = y[triang.triangles].mean(axis=1)
mask = np.where(xmid*xmid + ymid*ymid < min_radius*min_radius, 1, 0)
triang.set_mask(mask)
 
# pcolor plot.

src/m/a/matplotlib-HEAD/examples/pylab_examples/tricontour_demo.py   matplotlib(Download)
# Mask off unwanted triangles.
xmid = x[triang.triangles].mean(axis=1)
ymid = y[triang.triangles].mean(axis=1)
mask = np.where(xmid*xmid + ymid*ymid < min_radius*min_radius, 1, 0)
triang.set_mask(mask)
 
# pcolor plot.

src/m/a/matplotlib-HEAD/matplotlib/examples/pylab_examples/triplot_demo.py   matplotlib(Download)
# Mask off unwanted triangles.
xmid = x[triang.triangles].mean(axis=1)
ymid = y[triang.triangles].mean(axis=1)
mask = np.where(xmid*xmid + ymid*ymid < min_radius*min_radius, 1, 0)
triang.set_mask(mask)
 
# Plot the triangulation.

src/m/a/matplotlib-HEAD/examples/pylab_examples/triplot_demo.py   matplotlib(Download)
# Mask off unwanted triangles.
xmid = x[triang.triangles].mean(axis=1)
ymid = y[triang.triangles].mean(axis=1)
mask = np.where(xmid*xmid + ymid*ymid < min_radius*min_radius, 1, 0)
triang.set_mask(mask)
 
# Plot the triangulation.

src/p/y/pyopencl-0.92/examples/demo_mandelbrot.py   pyopencl(Download)
    for iter in range(maxiter):
        z = z*z + q
        done = np.greater(abs(z), 2.0)
        q = np.where(done,0+0j, q)
        z = np.where(done,0+0j, z)
        output = np.where(done, iter, output)
    return output

src/m/a/matplotlib-HEAD/toolkits/basemap/examples/plotmap_masked.py   matplotlib(Download)
# associate this axes with the Basemap instance.
m.ax = ax
# make topodat a masked array, masking values lower than sea level.
topodat = np.where(topodat < 0.,1.e10,topodat)
topodatm = ma.masked_values(topodat, 1.e10)
palette = plt.cm.YlOrRd
palette.set_bad('aqua', 1.0)

  1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9  Next