Numpy - add row to array

后端 未结 10 1362
难免孤独
难免孤独 2020-11-27 10:59

How does one add rows to a numpy array?

I have an array A:

A = array([[0, 1, 2], [0, 2, 0]])

I wish to add rows to this array from

10条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 11:27

    You can use numpy.append() to append a row to numpty array and reshape to a matrix later on.

    import numpy as np
    a = np.array([1,2])
    a = np.append(a, [3,4])
    print a
    # [1,2,3,4]
    # in your example
    A = [1,2]
    for row in X:
        A = np.append(A, row)
    

提交回复
热议问题