[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)
原文地址:https://www.cnblogs.com/cxc1357/p/10422143.html