Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 487 characters in body
Source Link
Alex Riley
  • 178.1k
  • 46
  • 274
  • 247

There are a few different ways you could do this. Here are a some examples:

Using np.c_:

np.c_[a, b, c] 

Using np.dstack and np.squeeze:

np.dstack((a, b, c)).squeeze() 

Using np.vstack and transpose (similar to your method):

np.vstack((a,b,c)).T 

Using np.concatenate and reshape:

np.concatenate((a, b, c)).reshape((-1, 3), order='F') 

If efficiency matters here, the last method using np.concatenate appears to be by far the quickest on my computer:

>>> %timeit np.c_[a, b, c] 10000 loops, best of 3: 46.7 us per loop >>> %timeit np.dstack((a, b, c)).squeeze() 100000 loops, best of 3: 18.2 us per loop >>> %timeit np.vstack((a,b,c)).T 100000 loops, best of 3: 17.8 us per loop >>> %timeit np.concatenate((a, b, c)).reshape((-1, 3), order='F') 100000 loops, best of 3: 3.41 us per loop 

There are a few different ways you could do this. Here are a some examples:

Using np.c_:

np.c_[a, b, c] 

Using np.dstack and np.squeeze:

np.dstack((a, b, c)).squeeze() 

Using np.vstack and transpose (similar to your method):

np.vstack((a,b,c)).T 

Using np.concatenate and reshape:

np.concatenate((a, b, c)).reshape((-1, 3), order='F') 

There are a few different ways you could do this. Here are a some examples:

Using np.c_:

np.c_[a, b, c] 

Using np.dstack and np.squeeze:

np.dstack((a, b, c)).squeeze() 

Using np.vstack and transpose (similar to your method):

np.vstack((a,b,c)).T 

Using np.concatenate and reshape:

np.concatenate((a, b, c)).reshape((-1, 3), order='F') 

If efficiency matters here, the last method using np.concatenate appears to be by far the quickest on my computer:

>>> %timeit np.c_[a, b, c] 10000 loops, best of 3: 46.7 us per loop >>> %timeit np.dstack((a, b, c)).squeeze() 100000 loops, best of 3: 18.2 us per loop >>> %timeit np.vstack((a,b,c)).T 100000 loops, best of 3: 17.8 us per loop >>> %timeit np.concatenate((a, b, c)).reshape((-1, 3), order='F') 100000 loops, best of 3: 3.41 us per loop 
Source Link
Alex Riley
  • 178.1k
  • 46
  • 274
  • 247

There are a few different ways you could do this. Here are a some examples:

Using np.c_:

np.c_[a, b, c] 

Using np.dstack and np.squeeze:

np.dstack((a, b, c)).squeeze() 

Using np.vstack and transpose (similar to your method):

np.vstack((a,b,c)).T 

Using np.concatenate and reshape:

np.concatenate((a, b, c)).reshape((-1, 3), order='F')