我正在尝试np.array通过从 python 生成器中采样来构造一个,每次调用next. 这是一些示例代码:
import numpy as np
data = np.eye(9)
labels = np.array([0,0,0,1,1,1,2,2,2])
def extract_one_class(X,labels,y):
""" Take an array of data X, a column vector array of labels, and one particular label y.  Return an array of all instances in X that have label y """
    return X[np.nonzero(labels[:] == y)[0],:]
def generate_points(data, labels, size):
""" Generate and return 'size' pairs of points drawn from different classes """
     label_alphabet = np.unique(labels)
     assert(label_alphabet.size > 1)
     for useless in xrange(size):
         shuffle(label_alphabet)
         first_class = extract_one_class(data,labels,label_alphabet[0])
         second_class = extract_one_class(data,labels,label_alphabet[1])
         pair = np.hstack((first_class[randint(0,first_class.shape[0]),:],second_class[randint(0,second_class.shape[0]),:]))
         yield pair
points = np.fromiter(generate_points(data,labels,5),dtype = np.dtype('f8',(2*data.shape[1],1)))
该extract_one_class函数返回一个数据子集:属于一个类标签的所有数据点。我想得到积分np.array。_ shape = (size,data.shape[1])目前上面的代码片段返回一个错误:
ValueError: setting an array element with a sequence.
fromiter声明返回一维数组的文档。还有一些人以前使用 fromiter 在 numpy 中构造记录数组(例如http://iam.al/post/21116450281/numpy-is-my-homeboy)。  
假设我可以以这种方式生成一个数组,我是否偏离了标准?还是我的 numpy 不太对劲?