when should i use hstack/vstack vs append vs concatenate vs column_stack

前端 未结 3 1163
情深已故
情深已故 2020-11-30 22:24

Simple question: what is the advantage of each of these methods. It seems that given the right parameters (and ndarray shapes) they all work seemingly equivalently. Do some

3条回答
  •  北荒
    北荒 (楼主)
    2020-11-30 22:55

    In IPython you can look at the source code of a function by typing its name followed by ??. Taking a look at hstack we can see that it's actually just a wrapper around concatenate (similarly with vstack and column_stack):

    np.hstack??
    def hstack(tup):
    ...
        arrs = [atleast_1d(_m) for _m in tup]
        # As a special case, dimension 0 of 1-dimensional arrays is "horizontal"
        if arrs[0].ndim == 1:
            return _nx.concatenate(arrs, 0)
        else:
            return _nx.concatenate(arrs, 1)
    

    So I guess just use whichever one has the most logical sounding name to you.

提交回复
热议问题