Create a function called mergeAndSeparate which performs the following tasks: Accepts two numpy arrays, aLeft and aRight Creates and returns three numpy arrays, left, right, and both both contains the elements in the arrays which match on value and position If aLeft = [1 2 4 4] and aRight = [1 6 5 4] then both should contain [1 4] (the first and last elements) left contains all of the elements in aLeft not matched in aRight In our previous example, left should contain [2 4], the middle two elements right contains all of the elements in aRight not matched in aLeft In our previous example, right should contain [6 5], the middle two elements Your code should use only numpy operations No loops. No if statements The function should not print anything You may assume that the input arrays are 1-dimensional and that they are the same length, but you do not know in advance how long they will be You may assume numpy has already been imported Hints: My solution is 5 lines long, not counting the function definition Yours doesn't need to be, but it should be fewer than 10 lines Numpy's equivalent to not is the tilde: ~ (it's on the left of the 1 key on most keyboards) That is, if you want to say "not x" in numpy, you say "~x" solve in python

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Create a function called mergeAndSeparate which performs the following tasks:

  • Accepts two numpy arrays, aLeft and aRight
  • Creates and returns three numpy arrays, left, right, and both
    • both contains the elements in the arrays which match on value and position
      • If aLeft = [1 2 4 4] and aRight = [1 6 5 4] then both should contain [1 4] (the first and last elements)
    • left contains all of the elements in aLeft not matched in aRight
      • In our previous example, left should contain [2 4], the middle two elements
    • right contains all of the elements in aRight not matched in aLeft
      • In our previous example, right should contain [6 5], the middle two elements
  • Your code should use only numpy operations
    • No loops. No if statements
  • The function should not print anything
  • You may assume that the input arrays are 1-dimensional and that they are the same length, but you do not know in advance how long they will be
  • You may assume numpy has already been imported

Hints:

  • My solution is 5 lines long, not counting the function definition
    • Yours doesn't need to be, but it should be fewer than 10 lines
  • Numpy's equivalent to not is the tilde: ~ (it's on the left of the 1 key on most keyboards)
    • That is, if you want to say "not x" in numpy, you say "~x"
    • solve in python
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY