Skip to content

Checklist of NumPy functions in Dask Array #2911

Open

Description

@jakirkham

Below is a rough list of functions in NumPy that may be useful in Dask Array. This has been curated based on what may be manageable in Dask. Sorting operations have been dropped for instance.

  • abs
  • absolute
  • add
  • all
  • allclose
  • amax
  • amin
  • angle
  • any
  • append
  • apply_along_axis
  • apply_over_axes
  • arange
  • arccos
  • arccosh
  • arcsin
  • arcsinh
  • arctan
  • arctan2
  • arctanh
  • argmax
  • argmin
  • argwhere
  • around
  • array_equal
  • array_equiv
  • array_split
  • asanyarray
  • asarray
  • asarray_chkfinite
  • asscalar
  • atleast_1d
  • atleast_2d
  • atleast_3d
  • average
  • bartlett
  • bincount
  • bitwise_and
  • bitwise_not
  • bitwise_or
  • bitwise_xor
  • blackman
  • block
  • bmat
  • broadcast
  • broadcast_arrays
  • broadcast_to
  • c_
  • can_cast
  • cast
  • cbrt
  • ceil
  • choose
  • clip
  • column_stack
  • compress
  • concatenate
  • conj
  • conjugate
  • convolve
  • copy
  • copysign
  • corrcoef
  • correlate
  • cos
  • cosh
  • count_nonzero
  • cov
  • cross
  • cumprod
  • cumsum
  • deg2rad
  • degrees
  • delete
  • diag
  • diag_indices
  • diag_indices_from
  • diagflat
  • diagonal
  • diff
  • digitize
  • divide
  • division
  • divmod
  • dot
  • dsplit
  • dstack
  • ediff1d
  • einsum
  • empty
  • empty_like
  • equal
  • euler_gamma
  • exp
  • exp2
  • expand_dims
  • expm1
  • extract
  • eye
  • fabs
  • fill_diagonal
  • fix
  • flatnonzero
  • flip
  • fliplr
  • flipud
  • float_power
  • floor
  • floor_divide
  • fmax
  • fmin
  • fmod
  • frexp
  • fromfunction
  • frompyfunc
  • full
  • full_like
  • fv
  • geomspace
  • gradient
  • greater
  • greater_equal
  • hamming
  • hanning
  • heaviside
  • histogram
  • histogram2d
  • histogramdd
  • hsplit
  • hstack
  • hypot
  • i0
  • identity
  • imag
  • in1d
  • index_exp
  • indices
  • inexact
  • inner
  • insert
  • interp
  • intersect1d
  • invert
  • ipmt
  • irr
  • isclose
  • iscomplex
  • iscomplexobj
  • isfinite
  • isin
  • isinf
  • isnan
  • isnat
  • isneginf
  • isposinf
  • isreal
  • isrealobj
  • isscalar
  • ix_
  • kaiser
  • kron
  • ldexp
  • left_shift
  • less
  • less_equal
  • linspace
  • log
  • log10
  • log1p
  • log2
  • logaddexp
  • logaddexp2
  • logical_and
  • logical_not
  • logical_or
  • logical_xor
  • logspace
  • mask_indices
  • matmul
  • max
  • maximum
  • mean
  • meshgrid
  • mgrid
  • min
  • minimum
  • mirr
  • mod
  • modf
  • moveaxis
  • multiply
  • nan_to_num
  • nanargmax
  • nanargmin
  • nancumprod
  • nancumsum
  • nanmax
  • nanmean
  • nanmin
  • nanprod
  • nanstd
  • nansum
  • nanvar
  • ndim
  • negative
  • nextafter
  • nonzero
  • not_equal
  • nper
  • npv
  • ogrid
  • ones
  • ones_like
  • outer
  • packbits
  • pad
  • piecewise
  • place
  • pmt
  • poly
  • poly1d
  • polyadd
  • polyder
  • polydiv
  • polyfit
  • polyint
  • polymul
  • polynomial
  • polysub
  • polyval
  • positive
  • power
  • ppmt
  • prod
  • product
  • ptp
  • put
  • putmask
  • pv
  • r_
  • rad2deg
  • radians
  • rate
  • ravel
  • ravel_multi_index
  • real
  • real_if_close
  • reciprocal
  • remainder
  • repeat
  • require
  • reshape
  • resize
  • result_type
  • right_shift
  • roll
  • rollaxis
  • roots
  • rot90
  • round
  • row_stack
  • select
  • setdiff1d
  • setxor1d
  • shape
  • sign
  • signbit
  • sin
  • sinc
  • sinh
  • size
  • spacing
  • split
  • sqrt
  • square
  • squeeze
  • stack
  • std
  • subtract
  • sum
  • swapaxes
  • take
  • tan
  • tanh
  • tensordot
  • tile
  • trace
  • transpose
  • trapz
  • tri
  • tril
  • tril_indices
  • tril_indices_from
  • trim_zeros
  • triu
  • triu_indices
  • triu_indices_from
  • true_divide
  • trunc
  • union1d
  • unique
  • unpackbits
  • unravel_index
  • unwrap
  • vander
  • var
  • vdot
  • vectorize
  • vsplit
  • vstack
  • where
  • zeros
  • zeros_like

Activity

  1. mrocklin commented on Dec 1, 2017

    @mrocklin
    Member

    Some quick first impressions:

    1. We might want to include operations like sort, but note that they probably aren't very doable
    2. Many of the missing ufuncs (divide, ceil, ...) are handled by __array_ufunc__. I guess there is still value to implementing these explicitly for older versions of NumPy.
    3. Some sort of grid layout might be more pleasant. I have no particular objection to moving this to the docs.
  2. jakirkham commented on Dec 5, 2017

    @jakirkham
    MemberAuthor

    Agreed.

    True. More generally we might want to survey what versions of NumPy are used with Dask. Not sure if this data is reported by conda somehow.

    Agreed. Will give it some thought during the migration to the docs.

    As more follow-up to the last point, are you thinking to group these as well? Should add am planning to add things like numpy.fft/da.fft and numpy.linalg/da.linalg. How do you imagine these fit in with the grid layout?

  3. mrocklin commented on Dec 5, 2017

    @mrocklin
    Member
  4. jakirkham commented on Dec 5, 2017

    @jakirkham
    MemberAuthor

    Ok. No worries. I'll try something when putting them in the docs and we can discuss in that PR in more detail.

  5. rabernat commented on Jun 26, 2018

    @rabernat
    Contributor

    I just encountered a need for a blocked histogram2d: https://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram2d.html

    I am voicing my support for adding this function to dask.

  6. rabernat commented on Sep 18, 2018

    @rabernat
    Contributor

    @dhruvbalwada: implementing histogram2d and histogramdd within dask would be an excellent way to proceed on the project we discussed regarding evaluating statistics of our high-resolution simulations. This would allow you to trivially compute, for example, the 2D histogram of vorticity and divergence for a very large dataset.

    Alternatively, we could try to use datashader for this.

  7. mrocklin commented on Sep 18, 2018

    @mrocklin
    Member
  8. horta commented on Jan 25, 2019

    @horta
    Contributor

    Isn't trace simply da.diag(K).sum())?

  9. jakirkham commented on Jan 25, 2019

    @jakirkham
    MemberAuthor

    A PR for this would be welcome. Assuming of course that this list isn’t missing some things.

  10. deeplycloudy commented on Jul 23, 2019

    @deeplycloudy

    I too had a need for histogram2d today, and so I made a run at what @mrocklin said should be possible. Below is an example that takes an xarray dataset and the names of the two variables to be histogrammed, as well as a tuple of explicit bin edges.

    def do_histo2d(da, **kwargs):
        # use an intermediate function to toss out the xbin, ybin arguments
        histo, xbin, ybin = np.histogram2d(da[0,:], da[1,:], **kwargs)
        return histo
    
    def dask_histogram2d(dataset, names, bins=None, chunksize=10000, dtype='i4'):
        if bins is None: raise ValueError('bins must be a 2-tuple of np.ndarray bin edges')
        output_shape = [b.shape[0]-1 for b in bins]
        das = [dataset[n].data.flatten() for n in names]
        histo_data = dask.array.vstack(das).rechunk((len(names),chunksize))
        res = dask.array.core.map_blocks(do_histo2d, histo_data,
                                         chunks=output_shape,
                                         dtype=dtype, bins=bins)
        return res, output_shape
    

    For my use case, I've preprocessed many large satellite images to select some pixels of interest that are stored in the xarray dataset glm_5_min. It has two data variables, flash_extent_density and average_flash_area, for which I have specified some explicit bin edges as numpy arrays. Calling dask_histogram2d looks like this:

    res, output_shape = dask_histogram2d(glm_5_min,
                            ('flash_extent_density', 'average_flash_area'),
                            bins=(fed_bins, afa_bins))
    histo=res.compute()
    reshaped = histo.reshape(output_shape[0], res.numblocks[1], output_shape[1]).sum(axis=1)
    

    reshaped has the same shape as the histo returned by np.histogram2d.

    I don't understand why histo has the shape it does. Figuring out that the number of blocks was the middle dimension took a couple hours of trial and error, probably because I don't understand how map_blocks works.

    I don't have time to turn this into a real PR right now, but if someone does feel free to run with it.

  11. dhruvbalwada commented on Jul 23, 2019

    @dhruvbalwada

    @deeplycloudy - could also look at https://xhistogram.readthedocs.io/ , which has been trying to address this. From personal experience it works quite smoothly :)

  12. deeplycloudy commented on Jul 23, 2019

    @deeplycloudy

    @dhruvbalwada Ah, very nice! Yes, a fully generalized, label-aware histogram is certainly useful. I'd love to see relevant parts upstreamed into xarray, dask, or even numpy. @mrocklin gave a nice talk at SciPy about the benefit of and need to work toward a unified, user-facing API across various libraries, and this is a great illustration of something universally useful that has to exist as a separate package right now. It makes it not as discoverable for folks starting from numpy and growing into dask/xarray.

  13. fredericoschardong commented on May 9, 2020

    @fredericoschardong

    Is there any particular reason not to include left_shift and right_shift?

  14. jakirkham commented on May 9, 2020

    @jakirkham
    MemberAuthor

    They are in the list 🙂

    It's worth noting that they are ufuncs. So you should just be able to use NumPy's functions on Dask Arrays as-is and things will be handled correctly under-the-hood 😉

  15. jakirkham commented on May 5, 2022

    @jakirkham
    MemberAuthor

    Also this listing/comparison may be useful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions