1. 程式人生 > >python中list,array,mat,tuple,以及.format()輸出格式

python中list,array,mat,tuple,以及.format()輸出格式

#coding: utf-8

from numpy import *

a=[1,2,3,4,5,6,7]
b=array([[1,2,3],[4,5,6]])
c=mat([[1,2,3],[4,5,6],[7,8,9]])
d=(0,2,4,5,6)
print("a:{}\ntype:{},shape:{}".format(a,type(a),shape(a)))
print("b:{}{}type:{},shape:{}".format(b,'\n',type(b),shape(b)))
print("c:{}\ntype:{},shape:{}".format(c,type(c),shape(c)))
print("d:{}\ntype:{},shape:{}".format(d,type(d),shape(d)))

#結果如下

a:[1, 2, 3, 4, 5, 6, 7]
type:<class 'list'>,shape:(7,)
b:[[1 2 3]
 [4 5 6]]
type:<class 'numpy.ndarray'>,shape:(2, 3)
c:[[1 2 3]
 [4 5 6]
 [7 8 9]]
type:<class 'numpy.matrixlib.defmatrix.matrix'>,shape:(3, 3)
d:(0, 2, 4, 5, 6)
type:<class 'tuple'>,shape:(5,)