Ask Your Question
2

What is the method to separate two values in a single column of a numpy array?

asked 2023-03-06 11:00:00 +0000

plato gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-05-28 02:00:00 +0000

scrum gravatar image

To separate two values in a single column of a numpy array, you can use the numpy "split" function.

For example, let's say you have an array "a" with two values in each row:

import numpy as np

a = np.array([[1, 2], [3, 4], [5, 6]])

To separate the two values in each row into separate columns, you can use the split function along the second axis:

a_split = np.split(a, 2, axis=1)

This will create a new array "a_split" with two columns, each containing one of the original values:

array([[[1],
        [3],
        [5]],

       [[2],
        [4],
        [6]]])
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-03-06 11:00:00 +0000

Seen: 14 times

Last updated: May 28 '22