0
X = data[['x_1','x_2']].as_matrix()
y = data['y'].as_matrix()

X_pos = np.array([[X[i]  for i in range(6)if y==1]])

y is a numpy array with some values of 0 and 1.

can somebody help me with the syntax ?

  X_pos = np.array([np.array([X[i]  for i in range(8)])[y[:8].astype('bool')]])
  X_neg = np.array([[np.logical_not(y)]])

Printing X_pos,

[[[ 1.          0.87142857  0.62458472]
  [ 1.         -0.02       -0.92358804]
  [ 1.          0.36285714 -0.31893688]
  [ 1.          0.88857143 -0.87043189]]]

When I print X_neg, I am getting only

[[[ True  True  True  True False False False False]]]

Instead I should get like this ,

[[ 1.         -0.80857143  0.8372093 ]
 [ 1.          0.35714286  0.85049834]
 [ 1.         -0.75142857 -0.73089701]
 [ 1.         -0.3         0.12624585]]
4
  • 2
    Why does it matter? The L just indicates a long integer, I'm not sure why you would be concerned about it. Commented Feb 17, 2017 at 21:30
  • I just got confused. can we print the shape without a L ?? Commented Feb 17, 2017 at 21:57
  • Why, though? Like, what is your goal? Are you putting the shape in a string and using it somehow? Do you dislike the letter L? Commented Feb 17, 2017 at 21:57
  • nope...I have seen print the shape without the letter L...so I got confused whether I have to typecast Commented Feb 17, 2017 at 21:59

1 Answer 1

1

assuming x and y are numpy arrays, your third line has the problem, you could rewrite it like that:

X_pos = np.array([np.array([X[i]  for i in range(6)])[y[:6].astype('bool')]])

for the fasle valuse (in y) use:

y_n = numpy.logical_not(y)
X_pos2 = np.array([np.array([X[i]  for i in range(6)])[y_n[:6]]])

here's what happen:

  • you take all the 6 elements of X

  • you apply a boolean mask of y elements for numpy array.

  • converting the whole result to numpy array (for some reason) as in your question..

Sign up to request clarification or add additional context in comments.

5 Comments

the above statement is for true conditions of y right ? @Yasin Yousif ? I need put the false conditions in another numpy array. How can I do it ?
it is mask of true and false ,..y , that the condition , but if u want the ommitted part , you can simply nigate y using numpy.logical_not(y)
I want to get the values of X whose y values are 0. # numpy.logical_not(y) from this I am getting true and false list.
Thanks @Yasin Yousif : Could you suggest me a link or material for learning typical numpy other than documentation ? Because doc couldn't help me in the above issue.
here it is, just learn the basic orders in numpy,then at every problem use auto complete , or docs (with good ide ,ex:spyder), try googling your problem with keyword:"numpy", Franckly , I learned numpy from opencv-python docs as start ,then just from the numpy docs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.