why does binary_repr don't support arrays
Hello, I'm always wondering why binary_repr doesn't allow arrays as input values. I always have to use a work around like: import numpy as np def binary_repr(arr, width=None): binary_list = map((lambda foo: np.binary_repr(foo, width)), arr.flatten()) str_len_max = len(np.binary_repr(arr.max(), width=width)) str_len_min = len(np.binary_repr(arr.min(), width=width)) if str_len_max > str_len_min: str_len = str_len_max else: str_len = str_len_min binary_array = np.fromiter(binary_list, dtype='|S'+str(str_len)) return binary_array.reshape(arr.shape) Is there a reason why arrays are not supported or is there another function that does support arrays? Thanks, Markus
On Tue, Oct 20, 2009 at 11:17 AM,
Hello,
I'm always wondering why binary_repr doesn't allow arrays as input values. I always have to use a work around like:
import numpy as np
def binary_repr(arr, width=None): binary_list = map((lambda foo: np.binary_repr(foo, width)), arr.flatten()) str_len_max = len(np.binary_repr(arr.max(), width=width)) str_len_min = len(np.binary_repr(arr.min(), width=width)) if str_len_max > str_len_min: str_len = str_len_max else: str_len = str_len_min binary_array = np.fromiter(binary_list, dtype='|S'+str(str_len)) return binary_array.reshape(arr.shape)
Is there a reason why arrays are not supported or is there another function that does support arrays?
Not sure if there was/is a reason, but imho it would be nice to have support for arrays. Also in base_repr. Could you file a ticket in trac? Cheers, Ralf
Thanks,
Markus _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
numpy-discussion-bounces@scipy.org schrieb am 22.10.2009 12:36:46:
On Tue, Oct 20, 2009 at 11:17 AM,
wrote: Hello,
I'm always wondering why binary_repr doesn't allow arrays as input values. I always have to use a work around like:
import numpy as np
def binary_repr(arr, width=None): binary_list = map((lambda foo: np.binary_repr(foo, width)),
arr.flatten())
str_len_max = len(np.binary_repr(arr.max(), width=width)) str_len_min = len(np.binary_repr(arr.min(), width=width)) if str_len_max > str_len_min: str_len = str_len_max else: str_len = str_len_min binary_array = np.fromiter(binary_list, dtype='|S'+str(str_len)) return binary_array.reshape(arr.shape)
Is there a reason why arrays are not supported or is there another function that does support arrays?
Not sure if there was/is a reason, but imho it would be nice to have support for arrays. Also in base_repr. Could you file a ticket in trac?
Cheers, Ralf
Okay, I opened a new ticket: http://projects.scipy.org/numpy/ticket/1270 Markus
participants (2)
-
markus.proeller@ifm.com
-
Ralf Gommers