0

After comparison between an array total= np.full((3,3),[0, 1, 2]) and array a = np.array([1],[0],[1]), I am looking to get a new_array:

array([[0, 2],
       [1, 2],
       [0, 2]])
3
  • Please explain the relationship between the input and output. You've got two answers that take two different interpretations of what you want, and it's not clear whether either of them performs the operation you actually want. Commented May 25, 2019 at 19:32
  • Both are correct Commented May 25, 2019 at 19:37
  • Both of them produce the output you specified for this particular pair of inputs, but return np.array([[0, 2], [1, 2], [0, 2]]) would also do that. They don't behave the same way as each other on other outputs. Commented May 25, 2019 at 19:55

2 Answers 2

1

You can use list comprehension and np.delete:

import numpy as np

total= np.full((3,3),[0, 1, 2])
a = np.array([[1],[0],[1]])

new_array = np.array([np.delete(l, i) for l,i in zip(total,a)])

result

array([[0, 2],
       [1, 2],
       [0, 2]])
Sign up to request clarification or add additional context in comments.

Comments

0

Can apply a mask and reshape:

import numpy as np

total= np.full((3,3),[0, 1, 2])
a = np.array([[1],[0],[1]])

a = np.repeat(a, 3, axis=1)
new_total = total[total!=a].reshape(3, 2)

>>> print(new_total)
[[0 2]
 [1 2]
 [0 2]]

Comments

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.