Skip to content
Advertisement

Tag: numpy-ndarray

Concatenating two one-dimensional NumPy arrays

How do I concatenate two one-dimensional arrays in NumPy? I tried numpy.concatenate: But I get an error: TypeError: only length-1 arrays can be converted to Python scalars Answer Use: The arrays you want to concatenate need to be passed in as a sequence, not as separate arguments. From the NumPy documentation: numpy.concatenate((a1, a2, …), axis=0) Join a sequence of arrays

How do I calculate percentiles with python/numpy?

Is there a convenient way to calculate percentiles for a sequence or single-dimensional numpy array? I am looking for something similar to Excel’s percentile function. I looked in NumPy’s statistics reference, and couldn’t find this. All I could find is the median (50th percentile), but not something more specific. Answer You might be interested in the SciPy Stats package. It

Convert NumPy array to Python list

How do I convert a NumPy array into a Python List? Answer Use tolist(): Note that this converts the values from whatever numpy type they may have (e.g. np.int32 or np.float32) to the “nearest compatible Python type” (in a list). If you want to preserve the numpy data types, you could call list() on your array instead, and you’ll end

Advertisement