pythonstatisticsquantile# Create this simple array

I have two one-dimensional arrays `u`

and `q`

as follows:

```
import numpy as np
n = 300
u1 = np.random.uniform(0.5, 4.5, size=n)
u2 = 2 / u1 + np.random.normal(scale=0.09, size=n)
u = np.array([u1,u2])
```

and

```
d=np.random.uniform(0.0, np.pi, size=100)
q = np.array([np.cos(d), np.sin(d)])
```

I have the following

```
np.max(np.quantile(np.dot(q[:, 0],u[:,]), 0.01))-np.max(np.quantile(np.dot(q[:, 0],u[:,]), 0.99))
```

for `q[:, 0]`

, but I want to have it for every `q[:,m]`

from m=1 to 100 (I mean for all columns of `q`

) and save them all in a new array.

How can I do that?

Solution

I'm not sure what you're trying to do and what result you expect. I'm going slow with my explanation so that if I got your idea wrong, you can modify my code to suit your need.

Replace `np.dot(q[:, 0],u[:,]`

with:

```
np.dot(q.transpose(), u)
```

The shape of `np.dot(q[:, 0],u[:,]`

is `(300)`

, and that of `np.dot(q.transpose(), u)`

is `(100, 300)`

. This basically dot-product each of 100 columns of `q`

with `u`

.

Replace your quantile operation with:

```
np.quantile(np.dot(q.transpose(), u), q=0.01, axis=-1)
# or q=0.99 for the other one
```

By specifying an axis, you restrict `quantile`

to only operate on that axis, rather than on the entire array. The result has shape `(100)`

.

Before, your quantile operation returns a scalar, so wrapping it in `np.max`

does nothing. Now it returns the max of a 100-size array. The final line should be:

```
np.max(np.quantile(np.dot(q.transpose(), u), q=0.01, axis=-1))
- np.max(np.quantile(np.dot(q.transpose(), u), q=0.99, axis=-1))
```

The result is a scalar.

- How do I get around HttpError 403 Insufficient Permission? (gmail API, Python)
- How to install Python3 in Google Cloud Platform for a Node app
- can't find a way to make this triangle pattern
- pycharm does not connect to console with python3.8
- How can I construct an array of unique objects?
- How to import a python file that is in the same directory as the file I am trying to run from outside of that directory?
- django ignore changed field in formset
- Google API quickstart.py error KeyError: '_module'
- Shift data in excel Sheet to left to remove empty cells and include Header names
- How do I fix a "url downloading" script that errors, "AttributeError: module 'urllib' has no attribute 'urlretrieve'"?
- Is there a way to make dis.dis() print code objects recursively, pre-Python 3.7?
- Discord.py- How to make the bot not interact with DMs
- Python - Use bins from one sns.histplot() for another / Extract bin information from an sns.histplot()
- Subclass Enum to add validation
- Highlight the changes or areas of discrepancy between the two images
- Ensurepip is not found despite successfully installing python3-venv and python3.8-venv
- List of tuples merging
- How to return a csv file/Pandas DataFrame in JSON format using FastAPI?
- Get total amount of free GPU memory and available using pytorch
- How to calculate the midpoints of each triangle edges of an icosahedron
- Problems with .exe file after converting it from .py. "ModuleNotFoundError: no module named 'selenium'"
- Getting user ID in TwitchIO
- Finding Successors of Successors in a Directed Graph in NetworkX
- How to create numpy.ndarray A from existing B using various functions depending on corresponding value in B?
- Using PySide's QtWebKit under Windows with py2exe
- Tuple problem with parameterized SQLite query
- Parallelizing, Multiprocessing, CSV writer
- How to effectively replace sentences in word document with python
- How do you check whether a number is divisible by another number?
- MinMaxScaler for a number of columns in a pandas DataFrame