我正在使用布尔数组从 numpy 数组中删除一些列。是否可以用列表做类似的事情?
#Set a numpy array of booleans to True if column datatype is "Categorical"
cols_to_remove = np.array([datatype == "Categorical" for datatype in datatypes])
#Make a new array without the "Categorical" columns
cat_data = data[:, -cols_to_remove] # data here is a 2D numpy array
#Trying to do the same for a list - this way doesn't work
cat_datatypes = datatypes[-cols_to_remove] # datatypes here is a 1D list