[Python] 二维数组初始化

3种方式:

import numpy
import pandas
#方式1:列表推导(list comprehension)
b=[[0]*3 for i in range(4)]
a = [b[i][j] for i in range(3) for j in range(2)]  
#删除列表中空字符        
li = [1,' ',3]  
new_list = [x for x in li if x!=' ']
#方式2:numpy.ndarray
c = numpy.zeros([10,10]) 
#方式3:pandas.DataFrame(带索引二维表格)
data = {'1':[0]*3,'2':[0]*3}
d = pandas.DataFrame(data)

 

posted @ 2021-07-27 09:58  cxc1357  阅读(347)  评论(0编辑  收藏  举报