How does NumPy’s transpose() method permute the axes of an array?

To transpose an array, NumPy just swaps the shape and stride information for each axis. Here are the strides: >>> arr.strides (64, 32, 8) >>> arr.transpose(1, 0, 2).strides (32, 64, 8) Notice that the transpose operation swapped the strides for axis 0 and axis 1. The lengths of these axes were also swapped (both lengths … Read more

Transposing a 1D NumPy array

It’s working exactly as it’s supposed to. The transpose of a 1D array is still a 1D array! (If you’re used to matlab, it fundamentally doesn’t have a concept of a 1D array. Matlab’s “1D” arrays are 2D.) If you want to turn your 1D vector into a 2D array and then transpose it, just … Read more

Javascript equivalent of Python’s zip function

2016 update: Here’s a snazzier Ecmascript 6 version: zip= rows=>rows[0].map((_,c)=>rows.map(row=>row[c])) Illustration equiv. to Python{zip(*args)}: > zip([[‘row0col0’, ‘row0col1’, ‘row0col2’], [‘row1col0’, ‘row1col1’, ‘row1col2’]]); [[“row0col0″,”row1col0”], [“row0col1″,”row1col1”], [“row0col2″,”row1col2”]] (and FizzyTea points out that ES6 has variadic argument syntax, so the following function definition will act like python, but see below for disclaimer… this will not be its own inverse … Read more

Transpose list of lists

Python 3: # short circuits at shortest nested list if table is jagged: list(map(list, zip(*l))) # discards no data if jagged and fills short nested lists with None list(map(list, itertools.zip_longest(*l, fillvalue=None))) Python 2: map(list, zip(*l)) [[1, 4, 7], [2, 5, 8], [3, 6, 9]] Explanation: There are two things we need to know to understand … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)