Question

I am trying to generate a grid for my dataset of 10 dimensions, while doing so I am following the code from http://pybrain.org/docs/tutorial/fnn.html. The code which I am implementing and throwing error is:

 ticks = arange(-3.,6.,0.2)
 X, Y = meshgrid(ticks, ticks)
 # need column vectors in dataset, not arrays
 griddata = ClassificationDataSet(10,1, nb_classes=3)
 for i in xrange(X.size):
      griddata.addSample([X.ravel()[i],Y.ravel()[i]], [0])

The error that I am getting is:

 File "a.py", line 224, in <module>
  griddata.addSample([X.ravel()[i], Y.ravel()[i]], [0])
 File "a.py", line 45, in addSample
  self.appendLinked(inp, target)
 File "a.py", line 216, in appendLinked
  self._appendUnlinked(l, args[i])
 File "a.py", line 198, in _appendUnlinked
  self.data[label][self.endmarker[label], :] = row
 ValueError: cannot copy sequence with size 2 to array axis with dimension 7

I am not getting how to correct the error.

Was it helpful?

Solution

The answer is already given by Python: dimensions are your problem. You create a dataset with 10 dimensions: ClassificationDataSet(in_dim, out_dim, class_num) as the first number is for dimensions. And then you try to add a sample with 2 dimensions to that dataset: griddata.addSample([in1, in2, in3..., in_last], [out1]). The example you provide here is exactly from the pybrain tutorial, just you wrongly copied that one number, the in_dimensions. It was 2 in the example. And then it should work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top