TransposeColumn

From OpenCog

The TransposeColumn is an executable Link that will create the matrix transpose of nested Links or collections of vector values.

The anticipated use is to take search results, typically from QueryLink, which are returned as rows, and to repackage them as vector-columns. This works effectively the same way as FloatColumn or LinkColumn, except that it will generate multiple columns in one go. Recall that Values correspond to C++ vectors, and are directly accessible as C++ 'std::vector<T>' types.

For example,

  TransposeColumn
      Number 1 2 3
      Number 4 5 6

when executed will return

  LinkValue
      FloatValue 1 4
      FloatValue 2 5
      FloatValue 3 6

NumberNode vectors are automatically converted to FloatValue; this is to avoid the RAM overhead of storing them into the AtomSpace. Use [[LinkSignature(cog-execute!

   (LinkSignature
        (Type 'Float32Value)
        (Minus (Time) (Number 2))
        (Time)
        (Plus (Time) (Number 2))))

Link]] if you wish to convert back to NumberNodes.

Similarly,

  TransposeColumn
     List
        List
           Item "a"
           Item "b"
           Item "c"
        List
           Item "d"
           Item "e"
           Item "f"

when executed, will return

     LinkValue
        LinkValue
           Item "a"
           Item "d"
        LinkValue
           Item "b"
           Item "e"
        LinkValue
           Item "c"
           Item "f"

The ListLink's are converted to LinkValue to avoid the overhead of storing the result in the AtomSpace. Use CollectionOfLink to convert the LinkValues to explicit Links.

A large, complicated example can be found in the examples/pattern-matcher/vector-column.scm example.

See also