Merge the three arrays provided to you to form a one 4x4 array. [Hint: Check the function np.transpose()] Input: Array 1: 3*3 [[7, 13, 14] [18, 10, 17] [11, 12, 19]] Array 2: 1-D array [16, 6, 1] Array 3: 1*4 array [[5, 8, 4, 3]]
Answers
Explanation:
one. 4x4 array. [Hint: Check the function np.transpose()] Input: Array 1: 3*3 [[7, 13, 14] [18, 10, 17] [11, 12, 19]] Array 2: 1-D array [16, 6, 1] Array 3: 1*4 array [[5, 8, 4, 3]].. .....
Merging arrays:
Merges the elements of one or more arrays together so that the values of one are appended to the end of the previous one. It returns the resulting array.
Code:
#include<iostream>
using namespace std;
void mergeArrays(int arr1[], int arr2[], int n1,
int n2, int arr3[])
{
int i = 0, j = 0, k = 0;
while (i<n1 && j <n2)
{
if (arr1[i] < arr2[j])
arr3[k++] = arr1[i++];
else
arr3[k++] = arr2[j++];
}
while (i < n1)
arr3[k++] = arr1[i++];
while (j < n2)
arr3[k++] = arr2[j++];
}
int main()
{
int arr1[] = {1, 3, 5, 7};
int n1 = sizeof(arr1) / sizeof(arr1[0]);
int arr2[] = {2, 4, 6, 8};
int n2 = sizeof(arr2) / sizeof(arr2[0]);
int arr3[n1+n2];
mergeArrays(arr1, arr2, n1, n2, arr3);
cout << "Array after merging" <<endl;
for (int i=0; i < n1+n2; i++)
cout << arr3[i] << " ";
return 0;
}
#SPJ3