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]
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])
Comments
Leave a comment