summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/defchararray.py2
-rw-r--r--numpy/random/mtrand/mtrand.pyx30
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