Given an integer array of size 10. Replace the odd number in numpy array with -1 ?Note: Generate the following arrayarray([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])Print the Numpy array.
Question
Given an integer array of size 10. Replace the odd number in numpy array with -1 ?Note: Generate the following arrayarray([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])Print the Numpy array.
Solution
Here is a step-by-step solution in Python using the numpy library:
Step 1: Import the numpy library
import numpy as np
Step 2: Create the numpy array
arr = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
Step 3: Replace the odd numbers with -1
arr[arr % 2 == 1] = -1
Step 4: Print the modified array
print(arr)
When you run this code, it will print the array with all odd numbers replaced by -1.
Similar Questions
Given a 1D array, negate all elements which are between 3 and 8 (both inclusive)?Note: Generate the following arrayarray([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])Print the Numpy array.
Which line of code will create a list of every other number from 0 to 10 in reverse in Python?array(10, 0, 2))array(range(10, 0, -2))list(range(0, 10, -2))list(range(10, 0, -2))
Complete the function count_odd_even() , which receives number of elements and array as input. Function should count number of even numbers and odd numbers in the array and print it.Input Format:No Need to read any input, as it is predefined.Output Format:Print the count of odd and even as: Odd = ODD_COUNTEven = EVEN_COUNTConstraints:1<=size<=10^9 1<=arr[ind]<=10^15Sample Input 1:1047 41 87 88 95 46 35 66 63 93Sample Output 1:Odd = 7Even = 3Sample Input 2:81 2 3 4 5 6 7 8Sample Output 2:Odd = 4Even = 4
Write a C function, which returns the smallest odd number in a given array, and 0 if no such number is found.int smallest_odd(int a[] , int len);
What is the output of the following code? arr = numpy.arange(10) arr A 1D array of numbers from 0 to 9 A 1D array of numbers from 1 to 10 A 1D array of numbers from 0 to 10 A 1D array of numbers from 1 to 9
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.