Long NumPy array can't be printed completely?

前端 未结 2 549
既然无缘
既然无缘 2021-01-14 20:08

I\'m trying to print the complete contents of two 1001x1 arrays, but Python only gives me truncated output something like this:

array([[5,45],
       [1,23         


        
2条回答
  •  有刺的猬
    2021-01-14 20:39

    I'm going to guess that you tried a simple statement like:

    print myarray
    

    ... rather than something more explicit like:

    for each_item in myarray:
        print each_item
    

    ... or even:

    print ', '.join([str(x) for x in myarray])
    

    The reason you're seeing elided output is, presumably, because numpy implements a _str_ method in its array class which tries to give a "reaasonable" default string representation of the array. They are, presumably, assuming that simple print statements will be used primarily for debugging, logging, or similar purposes and that reporting of results, or marshaling of results to other processes or storage, is going to be done using more explicit iterations over the data (as I've shown here).

提交回复
热议问题