Convert a matrix to a list of column-vectors

Gavin’s answer is simple and elegant. But if there are many columns, a much faster solution would be: lapply(seq_len(ncol(x)), function(i) x[,i]) The speed difference is 6x in the example below: > x <- matrix(1:1e6, 10) > system.time( as.list(data.frame(x)) ) user system elapsed 1.24 0.00 1.22 > system.time( lapply(seq_len(ncol(x)), function(i) x[,i]) ) user system elapsed 0.2 … Read more

Pretty print 2D list?

To make things interesting, let’s try with a bigger matrix: matrix = [ [“Ah!”, “We do have some Camembert”, “sir”], [“It’s a bit”, “runny”, “sir”], [“Well,”, “as a matter of fact it’s”, “very runny, sir”], [“I think it’s runnier”, “than you”, “like it, sir”] ] s = [[str(e) for e in row] for row in … Read more

In WebGL what are the differences between an attribute, a uniform, and a varying variable?

Copied directly from http://www.lighthouse3d.com/tutorials/glsl-tutorial/data-types-and-variables/. The actual site has much more detailed information and would be worthwhile to check out. Variable Qualifiers Qualifiers give a special meaning to the variable. The following qualifiers are available: const – The declaration is of a compile time constant. attribute – Global variables that may change per vertex, that are … Read more

Confusion between C++ and OpenGL matrix order (row-major vs column-major)

matrix notation used in opengl documentation does not describe in-memory layout for OpenGL matrices If think it’ll be easier if you drop/forget about the entire “row/column-major” thing. That’s because in addition to row/column major, the programmer can also decide how he would want to lay out the matrix in the memory (whether adjacent elements form … Read more