Discussion:
[Numpy-discussion] Help in understanding
subro
2015-08-14 05:01:27 UTC
Permalink
Hi,

I am new to NumPy, Can someone help me in understanding below code.
names = np.array(['Bob', 'Joe', 'Will', 'Bob', 'Will', 'Joe', 'Joe'])
data = np.random.random((7,4))
print data
[[ 0.85402649 0.12827655 0.5805555 0.86288236]
[ 0.30162683 0.45269508 0.98098039 0.1291469 ]
[ 0.21229924 0.37497112 0.57367496 0.08607771]
[ 0.302866 0.42160468 0.26879288 0.68032467]
[ 0.60612492 0.35210577 0.91355096 0.57872181]
[ 0.11583826 0.81988882 0.39214077 0.51377566]
[ 0.03767641 0.1920532 0.24872009 0.36068313]]
data[names == 'Bob']
array([[ 0.85402649, 0.12827655, 0.5805555 , 0.86288236],
[ 0.302866 , 0.42160468, 0.26879288, 0.68032467]])

Also, can someone help me where and how to practice NumPy?



--
View this message in context: http://numpy-discussion.10968.n7.nabble.com/Help-in-understanding-tp40827.html
Sent from the Numpy-discussion mailing list archive at Nabble.com.
Aditya Krishnamurthy
2015-08-14 07:06:08 UTC
Permalink
names == 'Bob' returns a boolean array [True, False, False, True, False,
False, False], and data[boolean_array] returns all those elements of data
where the boolean array is True. data is a list of 7 lists, so the two
lists corresponding to True values are returned.

Read the Numpy basics and Advanced Numpy chapters from Python for Data
Analysis by Wes McKinney, it is available ol.
Post by subro
Hi,
I am new to NumPy, Can someone help me in understanding below code.
names = np.array(['Bob', 'Joe', 'Will', 'Bob', 'Will', 'Joe', 'Joe'])
data = np.random.random((7,4))
print data
[[ 0.85402649 0.12827655 0.5805555 0.86288236]
[ 0.30162683 0.45269508 0.98098039 0.1291469 ]
[ 0.21229924 0.37497112 0.57367496 0.08607771]
[ 0.302866 0.42160468 0.26879288 0.68032467]
[ 0.60612492 0.35210577 0.91355096 0.57872181]
[ 0.11583826 0.81988882 0.39214077 0.51377566]
[ 0.03767641 0.1920532 0.24872009 0.36068313]]
data[names == 'Bob']
array([[ 0.85402649, 0.12827655, 0.5805555 , 0.86288236],
[ 0.302866 , 0.42160468, 0.26879288, 0.68032467]])
Also, can someone help me where and how to practice NumPy?
--
http://numpy-discussion.10968.n7.nabble.com/Help-in-understanding-tp40827.html
Sent from the Numpy-discussion mailing list archive at Nabble.com.
_______________________________________________
NumPy-Discussion mailing list
http://mail.scipy.org/mailman/listinfo/numpy-discussion
Loading...