Skip to content

implement block to stack arrays along multiple dimensions at once #455

Open
@gdementen

Description

@gdementen

The goal is to produce more easily arrays like this:

11122
11122
33344

I don't know what would be the best syntax for this. Generalize stack, concat, from_lists?

Assuming blocking along existing axes (ie "generalized concat"):

>>> arr1 = ndtest("a=a0,a1;b=b0..b2")
>>> arr2 = ndtest("a=a0,a1;b=b3,b4")
>>> arr3 = ndtest("a=a2;b=b0..b2")
>>> arr4 = ndtest("a=a2;b=b3,b4")
>>> block([[arr1, arr2],
...        [arr3, arr4]], axes=('a', 'b'))
a\b  b0  b1  b2  b3  b4
 a0   0   1   2   0   1
 a1   3   4   5   2   3
 a2   0   1   2   0   1
>>> # FWIW, in my concat branch, this is equivalent to :
>>> concat([concat([arr1, arr2], 'b'), 
...         concat([arr3, arr4], 'b')], 'a')

See
https://docs.scipy.org/doc/numpy/reference/generated/numpy.block.html#numpy.block

Notes:

  • I do not want to do any effort to support:

    AAAbb
    AAAbb
    cDDDD
    

    like np.block does, but if it comes naturally from the implementation (which is likely and I guess is
    probably the case for np.block), I do not think it is worth it to add an explicit check to disallow it.

  • I don't see any real value of providing both concat and block in the API, as concat could simply be a special case for block or vice-versa. There are edge cases with non-LArray types where it would not be equal, but I do not think they would justify having two functions instead of one.

  • It would be nifty if we could write:

    >>> block([[arr1, 0],
    ...        [0, arr4]], axes=('a', 'b'))
    a\b  b0  b1  b2  b3  b4
     a0   0   1   2   0   0
     a1   3   4   5   0   0
     a2   0   0   0   0   1

    But that would be a bit tricky to implement (even if theoretically possible).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions