RE: convert array to vector

Skip to first unread message

eli mizzou

Feb 1, 2013, 8:09:38 PM2/1/13
Hi all,

I want to convert an array of integers to a vector (as gov.sandia.cognition.math.matrix.Vector)!
for example here is my array: Integer[] arr = {10, 10, 10, 5, 0, 0, 5, 10,10,10};

I appreciate any hint.


Justin Basilico

Feb 1, 2013, 11:54:41 PM2/1/13
Hi Eli,

You can create it using a VectorFactory. We typically use one of the default ones (VectorFactory.getDenseDefault() for dense vectors or VectorFactory.getSparseDefault() for sparse vectors).

To get a feeling for the general way to construct them would be:

Vector v = VectorFactory.getDenseDefault().createVector(arr.length);
for (int i = 0; i < arr.length; i++)
    v.setElement(i, arr[i]);
// Now v is ready to go.

In the special case of an Integer array, you can turn it into a list and use one of the convenience creation methods:

Vector v1 = VectorFactory.getDenseDefault().copyValues(Arrays.asList(arr));

Thanks, : )

You received this message because you are subscribed to the Google Groups "Cognitive Foundry" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
For more options, visit

Reply all
Reply to author
0 new messages