icecube.clsim.tablemaker.numpy_extensions module

icecube.clsim.tablemaker.numpy_extensions.apply_along_axes(func1d, axis, arrs, *args)

Apply a function to 1-D slices along the given axis.

Execute func1d(a, *args) where func1d operates on a set of 1-D arrays and a is a 1-D slice of arr along axis.

Parameters:
  • func1d (function) – This function should accept 1-D arrays. It is applied to 1-D slices of arr along the specified axis.

  • axis (integer) – Axis along which arr is sliced.

  • arrs (tuple) – tuple of input arrays. All arrays must have the same shape

  • args (any) – Additional arguments to func1d.

Returns:

outarr – The output array. The shape of outarr is identical to the shape of arr, except along the axis dimension, where the length of outarr is equal to the size of the return value of func1d. If func1d returns a scalar outarr will have one fewer dimensions than arr.

Return type:

ndarray

See also

apply_over_axis

Apply a function over 1-D slices of a single array.

apply_over_axes

Apply a function repeatedly over multiple axes.

icecube.clsim.tablemaker.numpy_extensions.meshgrid_nd(*arrays, **kwargs)

Creates coordinate tensors from an arbitrary number of one-dimensional coordinate vectors. With 2 arguments, the behavior is identical to numpy.meshgrid.

This can be useful, e.g. for evaluating a function that takes ndarrays on an N-dimensional without resorting to numpy.vectorize or explicit loops.

The dimensions of the returned array are transposed: the coordinate given by the first argument varies most quickly, followed by the second, etc. This matches the behavior of numpy.meshgrid. To get an array with dimensions in lexographical order, pass lex_order=True:

>>> x,y,z=numpy.arange(0,3),numpy.arange(4,6),numpy.arange(7,10)
>>> X,Y,Z=numpy.meshgrid_nd(x,y,z,lex_order=False)
>>> X
array([[[0, 1, 2],
        [0, 1, 2]],
       [[0, 1, 2],
        [0, 1, 2]],
       [[0, 1, 2],
        [0, 1, 2]]])
>>> Y
array([[[4, 4, 4],
        [5, 5, 5]],
       [[4, 4, 4],
        [5, 5, 5]],
       [[4, 4, 4],
        [5, 5, 5]]])
>>> Z
array([[[7, 7, 7],
        [7, 7, 7]],
       [[8, 8, 8],
        [8, 8, 8]],
       [[9, 9, 9],
        [9, 9, 9]]])
>>> X,Y,Z=numpy.meshgrid_nd(x,y,z,lex_order=True)
>>> X
array([[[0, 0, 0],
        [0, 0, 0]],
       [[1, 1, 1],
        [1, 1, 1]],
       [[2, 2, 2],
        [2, 2, 2]]])
>>> Y
array([[[4, 4, 4],
        [5, 5, 5]],
       [[4, 4, 4],
        [5, 5, 5]],
       [[4, 4, 4],
        [5, 5, 5]]])
>>> Z
array([[[7, 8, 9],
        [7, 8, 9]],
       [[7, 8, 9],
        [7, 8, 9]],
       [[7, 8, 9],
        [7, 8, 9]]])