所有输入数组在Python np.stack中的形状必须相同

时间:2019-06-28 16:47:09

标签: python arrays numpy

我有一个核苷酸序列,我正在尝试将其转换为阵列。以下代码适用于具有999个序列的文件,不适用于小于或等于这些序列的任何文件。

示例代码如下

from sklearn.preprocessing import LabelEncoder, OneHotEncoder
integer_encoder = LabelEncoder()  
one_hot_encoder = OneHotEncoder(categories='auto')   
input_features = []

for sequence in sequences:
  integer_encoded = integer_encoder.fit_transform(list(sequence))
  integer_encoded = np.array(integer_encoded).reshape(-1, 1)
  one_hot_encoded = one_hot_encoder.fit_transform(integer_encoded)
  input_features.append(one_hot_encoded.toarray())

np.set_printoptions(threshold=40)
input_features = np.stack(input_features, axis = -1)

ValueError: all input arrays must have the same shape


预期输出为

DNA sequence 1#
AAGCGGGGGT.....GTGGTGTATA
one hot encoding of Sequence #1:

[[1.1.0.....1.0.1]
[0.0.0....0.0]]

0 个答案:

没有答案