Numpy Convert String Representation of Boolean Array To Boolean Array
问题 Is there a native numpy way to convert an array of string representations of booleans eg: ['True','False','True','False'] To an actual boolean array I can use for masking/indexing? I could do a for loop going through and rebuilding the array but for large arrays this is slow. 回答1: You should be able to do a boolean comparison, IIUC, whether the dtype is a string or object : >>> a = np.array(['True', 'False', 'True', 'False']) >>> a array(['True', 'False', 'True', 'False'], dtype='|S5') >>> a