NumPy: Pretty print tabular data

后端 未结 4 1533
陌清茗
陌清茗 2020-11-30 09:21

I would like to print NumPy tabular array data, so that it looks nice. R and database consoles seem to demonstrate good abilities to do this. However, NumPy\'s built-in prin

4条回答
  •  北海茫月
    2020-11-30 09:49

    you can take advantage of array comprehension and use printf format strings:

    for c1, c2, c3 in dat:  
        print "%2f | %8e | %s" % (c1, c2, c3)
    

    https://en.wikipedia.org/wiki/Printf_format_string
    And you can get even more customized if you go up to version 2.7

提交回复
热议问题