0

I have an array that looks like the one below (boston housing dataset)..

array = array([[  6.32000000e-03,   1.80000000e+01,   2.31000000e+00, ...,
          1.53000000e+01,   3.96900000e+02,   4.98000000e+00],
       [  2.73100000e-02,   0.00000000e+00,   7.07000000e+00, ...,
          1.78000000e+01,   3.96900000e+02,   9.14000000e+00],
       [  2.72900000e-02,   0.00000000e+00,   7.07000000e+00, ...,
          1.78000000e+01,   3.92830000e+02,   4.03000000e+00],

I can pick out a column like this:

column_zero = [:, np.newaxis][:, :, 5]

Which gives me something like

[[ 6.575]
 [ 6.421]
 [ 7.185]
 [ 6.998]
 [ 7.147]
 [ 6.43 ]
  ...

Thats cool however what if I wanted to make a three dimensional array based on three columns such as 5, 2 and 0?

[[ 6.575, item_0_column_2, item_0_column_0]
 [ 6.421, item_1_column_2, item_1_column_0]
 [ 7.185, item_2_column_2, item_2_column_0]
 [ 6.998, item_3_column_2, item_3_column_0]
 [ 7.147, item_4_column_2, item_4_column_0]
 [ 6.43 , item_5_column_2, item_5_column_0]
  ...

So basically to clarify, I want to construct an array of the columns 5, 2 and 0.

1 Answer 1

2

Is this what you want?

>>> a = np.random.randint(0, 9, (3,6))
>>> a
array([[7, 1, 7, 4, 2, 0],
       [7, 5, 7, 1, 8, 5],
       [3, 5, 5, 3, 5, 5]])

>>> a[:, [5, 2, 0]]
array([[0, 7, 7],
       [5, 7, 7],
       [5, 5, 3]])
Sign up to request clarification or add additional context in comments.

1 Comment

Ah yeah jeez, I forgot about that.. Thank you aha

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.