Problem Statement:Given an integer array of size 10. Print the index of elements which are multiple of 3.Note: Generate the following arrayarray([ 1, 3, 5, 7, 9, 11, 13, 15, 17, 19])Print the index of elements.
Question
Problem Statement:Given an integer array of size 10. Print the index of elements which are multiple of 3.Note: Generate the following arrayarray([ 1, 3, 5, 7, 9, 11, 13, 15, 17, 19])Print the index of elements.
Solution
Sure, here is the Python solution for your problem:
import numpy as np
# Given array
arr = np.array([1, 3, 5, 7, 9, 11, 13, 15, 17, 19])
# Find the indices of elements that are multiples of 3
indices = np.where(arr % 3 == 0)
# Print the indices
print(indices)
This script first imports the necessary numpy module. Then, it creates the given array. The np.where function is used to find the indices where the condition (the element is a multiple of 3) is True. Finally, it prints these indices.
Similar Questions
Problem Statement You are given a function, int ElementsAndIndices(int arr[], int n); The function takes an integer array 'arr' of size 'n' as its arguments. Implement the function to find and return the number of array elements which are equal to their index value in array i.e. arr[k] = k, 0 <= k < n. Note: Indexing starts from 0. Return -1 if 'arr' is empty or None in case of python Example: Input: 10 1 12 3 5 8 9 7 12 23 Output: 3 Explanation: Index Element 0 10 1 1 2 12 3 3 4 5 5 8 6 9 7 7 8 12 9 23 Elements at index {1, 3, 7} are equal to their index values {1, 3, 7} respectively. Since, these are 3 elements, thus, output is 3. The custom input format for the above case: 10 10 1 12 3 5 8 9 7 12 23 (The first line represents the size of the array, the second line represents the elements of the array) Sample input -3 0 1 3 5 7 Sample Output 1 The custom input format for the above case: 6 -3 0 1 3 5 7 (The first line represents the size of the array, the second line represents the elements of the array) Instructions : This is a template based question, DO NOT write the "main" function. Your code is judged by an automated system, do not write any additional welcome/greeting messages. "Save and Test" only checks for basic test cases, more rigorous cases will be used to judge your code while scoring. Additional score will be given for writing optimized code both in terms of memory and execution time.
Find which element and Indices are equal 3.5 marks Problem Statement You are given a function, def ElementsAndIndices(arr): The function takes an integer array 'arr' of size 'n' as its arguments. Implement the function to find and return the number of array elements which are equal to their index value in array i.e. arr[k] = k, 0 <= k < n. Note: Indexing starts from 0. Return -1 if 'arr' is empty or None in case of python Example: Input: 10 1 12 3 5 8 9 7 12 23 Output: 3 Explanation: Index Element 0 10 1 1 2 12 3 3 4 5 5 8 6 9 7 7 8 12 9 23 Elements at index {1, 3, 7} are equal to their index values {1, 3, 7} respectively. Since, these are 3 elements, thus, output is 3. The custom input format for the above case: 10 10 1 12 3 5 8 9 7 12 23 (The first line represents the size of the array, the second line represents the elements of the array) Sample input -3 0 1 3 5 7 Sample Output 1 The custom input format for the above case: 6 -3 0 1 3 5 7 (The first line represents the size of the array, the second line represents the elements of the array) Instructions : This is a template based question, DO NOT write the "main" function. Your code is judged by an automated system, do not write any additional welcome/greeting messages. "Save and Test" only checks for basic test cases, more rigorous cases will be used to judge your code while scoring. Additional score will be given for writing optimized code both in terms of memory and execution time. give java code
Create an integer array of size 10, where all the values should be 0 but the fifth value should be 1.Print the elements of array.
Print 1st 10 multiples of 3 using while loopi=11while(i<11): print(3*i) i=i+1i=1while(i<11): print(3*i) i=i+1i=1while(i<10): print(3*i) i=i-1None of the above
What is wrong with the following code?int n = 5;int array[5];int i = 3;array[n] = i;
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.