boolean « numpy « Python Data Type Q&A

Home
Python Data Type Q&A
1.array
2.date
3.dictionary
4.Format
5.integer
6.List
7.numpy
8.regex
9.string
10.tuple
Python Data Type Q&A » numpy » boolean 

1. How do I use a 2-d boolean array to select from a 1-d array on a per-row basis in numpy?    stackoverflow.com

Let me illustrate this question with an example:

import numpy

matrix = numpy.identity(5, dtype=bool) #Using identity as a convenient way to create an array with the invariant that there will only be one ...

2. Memory error (MemoryError) when creating a boolean NumPy array (Python)    stackoverflow.com

I'm using NumPy with Python 2.6.2. I'm trying to create a small (length 3), simple boolean array. The following gives me a MemoryError, which I think it ought not to.

import numpy ...

3. python, numpy boolean array: negation in where statement    stackoverflow.com

with:

import numpy as np
array = get_array()
I need to do the following thing:
for i in range(len(array)):
    if random.uniform(0, 1) < prob:
        array[i] ...

4. numpy boolean array with 1 bit entries    stackoverflow.com

Is there a way in numpy to create an array of booleans that uses just 1 bit for each entry? the standard np.bool type is 1 byte, but this way I use ...

5. Index a SciPy sparse matrix with an array of booleans    stackoverflow.com

NumPy arrays can be indexed with an array of booleans to select the rows corresponding to True entries:

>>> X = np.array([[1,2,3], [4,5,6], [7,8,9]])
>>> rows = np.array([True,False,True])
>>> X[rows]
array([[1, 2, 3],
   ...

6. Efficient serialization of numpy boolean arrays    stackoverflow.com

I have hundreds of thousands of NumPy boolean arrays that I would like to use as keys to a dictionary. (The values of this dictionary are the number of times we've ...

7. Understanding weird boolean 2d-array indexing behavior in numpy    stackoverflow.com

Why does this work:

a=np.random.rand(10,20)
x_range=np.arange(10)
y_range=np.arange(20)

a_tmp=a[x_range<5,:]
b=a_tmp[:,np.in1d(y_range,[3,4,8])]
and this does not:
a=np.random.rand(10,20)
x_range=np.arange(10)
y_range=np.arange(20)    

b=a[x_range<5,np.in1d(y_range,[3,4,8])]

8. How to turn a boolean array into index array in numpy    stackoverflow.com

Is there an efficient Numpy mechanism to retrieve the integer indexes of locations in an array based on a condition is true as opposed to the Boolean mask array? For example:

x=np.array([range(100,1,-1)])
#generate a ...

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.