diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-12-09 20:00:27 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-12-09 20:00:27 +0000 |
commit | 6d8631d90dc03603ce7c0482ccdb16bf3a88d4d3 (patch) | |
tree | 83a57fb1a7af6d9251a9b37f297defa225873de0 /numpy | |
parent | db487c204c9df0472642d14d80632382463ecbcc (diff) | |
download | numpy-6d8631d90dc03603ce7c0482ccdb16bf3a88d4d3.tar.gz |
Fix shuffle and chararray printing for empty strings.
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/defchararray.py | 2 | ||||
-rw-r--r-- | numpy/random/mtrand/mtrand.pyx | 30 |
2 files changed, 26 insertions, 6 deletions
diff --git a/numpy/core/defchararray.py b/numpy/core/defchararray.py index 80822328c..39492b421 100644 --- a/numpy/core/defchararray.py +++ b/numpy/core/defchararray.py @@ -47,7 +47,7 @@ class chararray(ndarray): if isinstance(val, (string_, unicode_)): temp = val.rstrip() if len(temp) == 0: - val = val[0] + val = '' else: val = temp return val diff --git a/numpy/random/mtrand/mtrand.pyx b/numpy/random/mtrand/mtrand.pyx index 9bbb82e3c..9bff5b038 100644 --- a/numpy/random/mtrand/mtrand.pyx +++ b/numpy/random/mtrand/mtrand.pyx @@ -1206,13 +1206,33 @@ cdef class RandomState: shuffle(x) """ cdef long i, j + cdef int copy=0 - # adaptation of random.shuffle() i = len(x) - 1 - while i > 0: - j = rk_interval(i, self.internal_state) - x[i], x[j] = x[j], x[i] - i = i - 1 + try: + j = len(x[0]) + except: + j = 0 + + if (j == 0): + # adaptation of random.shuffle() + while i > 0: + j = rk_interval(i, self.internal_state) + x[i], x[j] = x[j], x[i] + i = i - 1 + else: + # make copies + copy = hasattr(x[0].copy) + if copy: + while(i > 0): + j = rk_interval(i, self.internal_state) + x[i], x[j] = x[j].copy(), x[i].copy() + i = i - 1 + else: + while(i > 0): + j = rk_interval(i, self.internal_state) + x[i], x[j] = x[j][:], x[i][:] + i = i - 1 def permutation(self, object x): """Given an integer, return a shuffled sequence of integers >= 0 and |