- Join over
**1.5M+ people** - Join over
**100K+ communities** - Free
**without limits** - Create
**your own community**

then with np.where fill in the 3 if else clauses

Something like this should work

```
has_value = s[1:-1, :] > -999.99
has_left = s[:-2, :] > -999.99
has_right = s[2:, :] > -999.99
dsdx = np.where(has_right & has_value, (s[2:, :] - s[1:-1, :]) / di, -1000)
dsdx = np.where(has_left & has_value, (s[1:-1, :] - s[:-2, :]) / di, dsdx)
dsdx = np.where(has_left & has_right, (s[2:, :] - s[:-2, :]) / (2. * di), dsdx)
```

Good evening! I've got a 3D array, and I want to map the values along a specific axis. *inner* array to be reshaped

`apply_along_axis()`

does this, however, the mapping function's return value is a list/array, and `apply_along_axis()`

then changes the result's outer shape to match that, while I want the
In other words, my data set is an array of matrices of 200x200 integers, and I want the result to be an array of matrices of 200x200 lists/arrays

I've checked the API docs for

`apply_along_axis()`

as well as for other functions, but nothing seems to stand out.
How would I get the shape I'm looking for?

That's a bit suboptimal.

I have a python script that takes the text file as input(inputfile defined inside a python script) and does some calculation(myscript.py). Now i want to run the same python script(myscript.py) inside the shell script so i did like

python my_shell.sh and i defined the input file a inputfile='data.txt' inside the shell script. (in simple language i need to run a python script over a data file but data file should be defined inside a shell script) I tried a lot but i am getting error like input file

1 2 3

4 5 6

7 8 9

c1 = np.loadtxt(inputfile)[:,0]

NameError: name 'inputfile' is not defined.

my python programme is like this

import numpy as np

c1 = np.loadtxt(inputfile)[:,0]

c2 = np.loadtxt(inputfile)[:,1]

c3 = np.loadtxt(inputfile)[:,2]

def function(x):

```
c1,c2,c3 = x
d=(c1+c2+c3)
return d
```

print(function([c1,c2,c3]))

then i call this programme from shell script

inputfile='data.txt'

python myscript.py

please find my files unable to rectify ....please help me on this https://i.fluffy.cc/zJ5VSv9mvjsz7kDGfqNkDSVf2SR62wqM.html

Dear experts i have a problem, I have a file that contain both numerics,strings and separator like .....how to import it using numpy.loadtxt

while loading

import numpy as np

np.loadtxt('file',dtype=str)

i am getting error like Convert each value according to its column and store

ValueError: Wrong number of columns at line 3

data file

```
10.0 c1
80.0 c2
...............
10.0 mr
2.0 no
```

Good evening! I tried updating numpy to 1.19 with conda but it does not seem to be available neither at the anaconda channel nor the conda-forge channel. This search showed 1.18.5 but not 1.19: https://anaconda.org/search?q=numpy. Is a conda release of 1.19 in the works?

The inaugural NumPy community survey is LIVE! Spare 15 minutes of your time to help the project in a big way! Your responses will help the leadership team to better guide and prioritize decision-making about the development of NumPy as software and a community.

To engage non-English speaking stakeholders, the survey is offered in 8 additional languages: Bangla, French, Hindi, Japanese, Mandarin, Portuguese, Russian, and Spanish.

It will take about 15 minutes of your time. Follow the link to get started: https://umdsurvey.umd.edu/jfe/form/SV_8bJrXjbhXf7saAl

To engage non-English speaking stakeholders, the survey is offered in 8 additional languages: Bangla, French, Hindi, Japanese, Mandarin, Portuguese, Russian, and Spanish.

It will take about 15 minutes of your time. Follow the link to get started: https://umdsurvey.umd.edu/jfe/form/SV_8bJrXjbhXf7saAl

Is this a reliable way to make a "deterministic" random sampler? Any way the output actually deviates from desired probabilities?

```
def _random_choice(probabilities, identifier):
np.random.seed(identifier)
choice = np.random.choice(range(len(probabilities)), p=probabilities)
return choice
```

But across different identifiers I want them to be random

If I take only one choice for each

`identifier`

, will the proportion of choices match `probabilities`

, and is there any noticeable correlation between some characteristic of the `identifier`

and the `choice`

?
It's like I want to make a random sampling by

`identifier`

but I don't know who they are beforehand
Dont use np.random. Use rg= np.random.default_rng(seed) which return an instance of a Generator that holds the state of the underlying BitGenerator that actually produces a stream of pseudorandom bytes. Then you call methods of that instance: rg.choice(...) etc. check out the documentation https://numpy.org/devdocs/reference/random/index.html for more info

Hi. I am writing Python logic in C++ for speed (with pybind11). I am receiving arguments, which are expected to be numpy array or convertible to such object.

In practice I am doing a check `py::isinstance(arg, py::array)`

. When it's not a numpy array, I would like to convert it. Thus, I would like to call `np.array(a)`

but from C++.

First option is to import numpy.array, and call if from C++, but it will go back to Python to go immediately back to C++ (seems to be unwanted).

I have found the C++ function associated to this:

https://github.com/numpy/numpy/blob/d3eae8be4d783948a0d71363bc07558524e905e5/numpy/core/src/multiarray/multiarraymodule.c#L3979 `_array_fromobject`

.

In practice, i guess I would like to call it, but it's not exposed in any header. Is there an alternative? Do you have any advice?

EDIT: I guess I want `asarray`

and not just `array`

.

It *might* be warranted to make ma.masked support hashing, although that might not actually help with anything given that

`masked == masked`

doesnt return true
1 reply

I am unable to understand why the quantile calculation using numpy differ with the manual calculation, could someone please suggest on below code:

```
#!/usr/bin/python3
import numpy as np
data = np.array([29.714498, 31.593990, 35.978494, 71.621345, 73.060123,
79.839773, 91.201094, 93.538623, 95.967625, 111.286755,
152.131551, 158.890394, 162.079048, 183.674307, 200.263680,
204.271583, 204.919013, 205.322027, 213.583217, 234.791289,
242.200068, 292.154278, 301.285016, 302.870495, 331.163927,
368.068559, 391.237075, 431.096627, 1607.974257, 1900.303876
])
# Using numpy value = 94.1458735
print("Numpy Calculation = ", np.quantile(data, .25, interpolation='linear'))
# Manual calculation value = 92.95424075
# Calculate location manually Ly = (n + 1) X (y/100)
location = (data.size + 1)*(25/100)
print("Location = ", location)
# Location comes out to be 7.75 which means 7th element + .75 of (8th - 7th)
value = data[6] + ((data[7] - data[6]) * .75)
print("Manual Calculation = ", value)
```

Here is the detail on the formula: https://ift.world/concept1/concept-6-quartiles-quintiles-deciles-percentiles/ and I am trying to find value of first quartile i.e. 25%

See numpy/numpy#10736 for a long discussion about this, in particular this image from that thread:

The red line is a mode not supported by numpy, that might be the one you're asking for