<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Set routines
Step1:  Making proper sets
Q1. Get unique elements and reconstruction indices from x. And reconstruct x.
Step2:  Boolean operations
Q2. Create a boolean array of the same shape as x. If each element of x is present in y, the result will be True, otherwise False.
Step3:  Q3. Find the unique intersection of x and y.
Step4:  Q4. Find the unique elements of x that are not present in y.
Step5:  Q5. Find the xor elements of x and y.
Step6:  Q6. Find the union of x and y.
<ASSISTANT_TASK:>
Python Code:
import numpy as np
np.__version__
author = 'kyubyong. longinglove@nate.com'
Explanation: Set routines
End of explanation
x = np.array([1, 2, 6, 4, 2, 3, 2])
out, indices = np.unique(x, return_inverse=True)
print "unique elements =", out
print "reconstruction indices =", indices
print "reconstructed =", out[indices]
Explanation: Making proper sets
Q1. Get unique elements and reconstruction indices from x. And reconstruct x.
End of explanation
x = np.array([0, 1, 2, 5, 0])
y = np.array([0, 1])
print np.in1d(x, y)
Explanation: Boolean operations
Q2. Create a boolean array of the same shape as x. If each element of x is present in y, the result will be True, otherwise False.
End of explanation
x = np.array([0, 1, 2, 5, 0])
y = np.array([0, 1, 4])
print np.intersect1d(x, y)
Explanation: Q3. Find the unique intersection of x and y.
End of explanation
x = np.array([0, 1, 2, 5, 0])
y = np.array([0, 1, 4])
print np.setdiff1d(x, y)
Explanation: Q4. Find the unique elements of x that are not present in y.
End of explanation
x = np.array([0, 1, 2, 5, 0])
y = np.array([0, 1, 4])
out1 = np.setxor1d(x, y)
out2 = np.sort(np.concatenate((np.setdiff1d(x, y), np.setdiff1d(y, x))))
assert np.allclose(out1, out2)
print out1
Explanation: Q5. Find the xor elements of x and y.
End of explanation
x = np.array([0, 1, 2, 5, 0])
y = np.array([0, 1, 4])
out1 = np.union1d(x, y)
out2 = np.sort(np.unique(np.concatenate((x, y))))
assert np.allclose(out1, out2)
print np.union1d(x, y)
Explanation: Q6. Find the union of x and y.
End of explanation
<END_TASK>