diff options
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/function_base.py | 4 | ||||
-rw-r--r-- | numpy/lib/npyio.py | 16 |
2 files changed, 16 insertions, 4 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index ca82bb72d..fb5dd6fdd 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -4000,7 +4000,7 @@ def percentile(a, With 'i' being the floor and 'g' the fractional part of the result. .. math:: - i + g = (q - alpha) / ( n - alpha - beta + 1 ) + i + g = q * ( n - alpha - beta + 1 ) + alpha The different methods then work as follows @@ -4279,7 +4279,7 @@ def quantile(a, and alpha and beta are correction constants modifying i and j: .. math:: - i + g = (q - alpha) / ( n - alpha - beta + 1 ) + i + g = q * ( n - alpha - beta + 1 ) + alpha The different methods then work as follows diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index 52bcf25f8..471f85976 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -1067,8 +1067,6 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None, r""" Load data from a text file. - Each row in the text file must have the same number of values. - Parameters ---------- fname : file, str, pathlib.Path, list of str, generator @@ -1171,6 +1169,11 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None, `genfromtxt` function provides more sophisticated handling of, e.g., lines with missing values. + Each row in the input text file must have the same number of values to be + able to read all values. If all rows do not have same number of values, a + subset of up to n columns (where n is the least number of values present + in all rows) can be read by specifying the columns via `usecols`. + .. versionadded:: 1.10.0 The strings produced by the Python float.hex method can be used as @@ -1279,6 +1282,15 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None, >>> np.loadtxt(s, dtype="U", delimiter=",", quotechar='"') array('Hello, my name is "Monty"!', dtype='<U26') + Read subset of columns when all rows do not contain equal number of values: + + >>> d = StringIO("1 2\n2 4\n3 9 12\n4 16 20") + >>> np.loadtxt(d, usecols=(0, 1)) + array([[ 1., 2.], + [ 2., 4.], + [ 3., 9.], + [ 4., 16.]]) + """ if like is not None: |