Answer to Question #311823 in Python for xxx

Question #311823

Question 9

print("Original array:")

Answer: 

print(x)

>>>array([ 11, 12, 13, 14, 15, 16, 17, 18, 19, 20])

print(“Remove even numbers from the array x: “)

Answer:

print(x)

>>>array([12, 14, 16, 18, 200])

print(“Replace all odd numbers in array x with -10:”)

Answer:

print(x)

>>> array([ 12, -10, 14, -10, 16, -10, 18, -10, 20])


Question 10

print("Original array:")

Answer: 

>>> print(X)

[10 12 14 16 18 20 22 24 26 28 30]

>>> print(Z)

[10 12 14 16 18 20 22 24 26 28 30]

Answer: 

>>> print(X)

[0 2 4 6 18 20 22 24 26 28 30]

Answer: 

>>> print(Z)

[10,12,14,16,-18,-20,-22,-24,26,28,30]


1
Expert's answer
2022-03-15T12:12:30-0400
import numpy as np
x = np.array([ 11, 12, 13, 14, 15, 16, 17, 18, 19, 20])
list1 = np.array([i for i in x if i % 2 != 0])
list1
array([11, 13, 15, 17, 19])

list1 = []
for i in x:
    if i % 2 != 0:
        list1.append(-10)
    else:
        list1.append(i)
np.array(list1)

array([-10,  12, -10,  14, -10,  16, -10,  18, -10,  20])

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS