array_split.split.shape_factors

array_split.split.shape_factors(n, dim=2)[source]

Returns a numpy.ndarray of factors f such that (len(f) == dim) and (numpy.product(f) == n). The returned factors are as square (cubic, etc) as possible. For example:

>>> shape_factors(24, 1)
array([24])
>>> shape_factors(24, 2)
array([4, 6])
>>> shape_factors(24, 3)
array([2, 3, 4])
>>> shape_factors(24, 4)
array([2, 2, 2, 3])
>>> shape_factors(24, 5)
array([1, 2, 2, 2, 3])
>>> shape_factors(24, 6)
array([1, 1, 2, 2, 2, 3])
Parameters:
  • n (int) – Integer which is factored into dim factors.
  • dim (int) – Number of factors.
Return type:

numpy.ndarray

Returns:

A (dim,) shaped array of integers which are factors of n.