These are chat archives for numpy/numpy

Jun 2016
Seb James
Jun 16 2016 10:23
Thanks for that @dhirschfeld It wasn't quite what I wanted - I wanted to use the 0th column of a as the indices into a, with the 1st column holding values. I found a solution with np.in1d:
In [10]: a = np.array([[1,2],[2,4],[4,8],[9,16]])

In [11]: indices=np.array([1,4]) 

In [12]: indices_mask = np.in1d(a[:,0], indices, assume_unique=True)

In [13]: indices_mask
Out[13]: array([ True, False,  True, False], dtype=bool)

In [14]: a[indices_mask]
array([[1, 2],
       [4, 8]])

In [15]:
Michael Seifert
Jun 16 2016 23:30
Is there some directly callable numpy function that evaluates False when the dtype cannot be safely cast to another dtype (like numpy.ndarray.astype(other_dtype, casting='safe')) or True if it can be safely converted - but without doing the actual casting?
Nathaniel J. Smith
Jun 16 2016 23:37
Michael Seifert
Jun 16 2016 23:41
@njsmith perfect, thank you!