1

Is there any efficient way to convert a 1D array like

[1,2,3] 

to a 3D array like

[[(1,1),(1,2),(1,3)],
 [(2,1),(2,2),(2,3)],
 [(3,1),(3,2),(3,3)]]

in Numpy/Python?

A.M.
  • 1,757
  • 5
  • 22
  • 41
  • y=[[(j,i) for i in x] for j in x] works. But I am assuming it is not efficient enough for your purposes? – Akshat Harit Jul 22 '15 at 20:23
  • Could you be more specific? Nothing you've shown is an array -- you have a list, and then a list of lists of tuples -- and your output object would need to be a 3D array, not a 2D array, in numpy if the underlying elements are intended to be integers. – DSM Jul 22 '15 at 20:24
  • @AkshatHarit Thanks. – A.M. Jul 22 '15 at 20:26
  • @DSM I am basically looking for sorted list of tuples. I have also edited the 3D thing. Thanks. – A.M. Jul 22 '15 at 20:27
  • A.M.: I don't think you're following the difference between Python native types (which can contain different objects) and numpy's array type (which can't, not really). On the bright side I think both @AkshatHarit's suggestion and the linked answer should give you what you need. – DSM Jul 22 '15 at 20:33
  • @DSM You are right. Both of them are very useful. Thanks :) – A.M. Jul 22 '15 at 20:33

0 Answers0