我有这个连接两个数组的代码。
import numpy as np
from hmmlearn import hmm
model = hmm.MultinomialHMM(n_components=3, n_iter=10,algorithm='map',tol=0.00001)
sequence3 = np.array([[2, 1, 0, 1]]).T
sequence4 = np.array([[2, 1, 0, 1, 1]]).T
sample = np.concatenate([sequence3, sequence4])
lengths = [len(sequence3), len(sequence4)]
model.fit(sample,lengths)
它工作正常。但是现在如果我有两个以上的数组。让我们说我有 10 个数组。我怎么能做同样的过程?
import numpy as np
from hmmlearn import hmm
model = hmm.MultinomialHMM(n_components=3, n_iter=10,algorithm='map',tol=0.00001)
sample = np.array([])
lengths = []
for i in range(1:10)
?????????????
model.fit(sample,lengths)
为了连接多个数组,您只需将数组与之前所有数组的连接连接起来。
# Create arrays
arrays=[
np.array([1,2,3]),
np.array([4,5,6]),
np.array([7,8,9])
]
# Create an array to return to
sample = np.array([])
for array in arrays:
sample = np.concatenate([sample, array])
# Print results
print('sample', sample)
print('length', len(sample))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句