Answer the question
In order to leave comments, you need to log in
How to replace some array values?
The question may seem cumbersome, but it is very simple.
I have two arrays: a1
and a2
. In the array a1
, all elements of type int, in the array a2
there are both int and str (in random order, they are scattered there).
If you write , then the output is something like this:for i in list(zip(a1, a2)): print(i)
...
(array([ 1.]), array([ nan]))
(array([ 1.]), array([ 2.]))
(array([ 2.]), array([ nan]))
(array([ 1.]), array([ nan]))
(array([ 2.]), array([ 1.]))
...
array([ 1.]
[ 2.]
[ 2.]
[ 1.]
[ 1.])
for i in list(zip(a1, a2)):
if isinstance(i[1], int):
i[0] == i[1]
a3 = [i[0] == i[1] for i in list(zip(a1, a2)) if isinsance(i[1], int)]
Answer the question
In order to leave comments, you need to log in
Timebird
is not suitable?
for i, e in enumerate(a2):
if isinstance(e, int):
a1[i] = e
what's my mistake?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question