Is the numpy.irr function correct?
This question may have an obvious answer that I am just missing. I am looking through the source code for numpy.irr and getting a bit confused about how they are going about solving it. IRR is found by solving
for irr. However, in the numpy code it solves the polynomial
for x, then returns 1/x  1 as the IRR. I might be mistaken, but these don't seem to be equivalent operations. They are close, but it seems that there would be situations in which the two numbers could be very different. Is there another library that has a more accurate IRR, or would I be better off creating my own function?
1 answer

I might be mistaken, but these don't seem to be equivalent operations.
You're mistaken. Those are equivalent operations.
See also questions close to this topic

Ajax using JavaScript by a chrome Extension  Error blocked crossorigin response with MIME type application/json
Failed to get a respond after Ajax a simple Array from JS by chrome extension to my backend "python"
error appears in console :
CrossOrigin Read Blocking (CORB) blocked crossorigin response http://127.0.0.1:5000/test with MIME type application/json. See https://www.chromestatus.com/feature/5629709824032768 for more details
I've tried to check
https://www.chromestatus.com/feature/5629709824032768
and
https://www.chromium.org/Home/chromiumsecurity/corbfordevelopers
what i've learned from reading those two resources is why they have created CORB OR CORS but it doesn't suggest any example that would work for all dev or maybe i've got lost in the middle of it somehow , i'm not sure what i should do or add to my code
mainfest:
{ "manifest_version": 2, "name": "testExtention", "description": "test extention", "browser_action" : { "default_title" : "hello computer!", "default_popup" : "popup.html" }, "background": { "scripts": ["background.js"] }, "content_scripts": [ { "matches": ["https://www.example.com/*", "https://m.example.com/*"], "js": ["content.js"] }], "version": "1.0", "permissions": [ "tabs", "storage" ,"http://127.0.0.1:5000/*" ] }
my js Ajax code:
const req = new XMLHttpRequest(); req.open('POST' , "http://127.0.0.1:5000/test"); req.onload = ()=>{ var res = JSON.parse(req.responseText); console.log('the response from the server = > ',res) } const data = new FormData(); data.append('x', y); req.send(data);
python:
@app.route("/test" ,methods = ["POST"] ) def req(): reqList = request.form.get("x") print(f'ive recieved this \n\n {x}') // x is printed fine. return jsonify({"success":reqList})
i can see in the console that Python have received and printed the AJAX object but haven't send the response to the javaScript

How to set a breakpoint in threaded Python?
I'm trying to set a breakpoint and it complains with
ValueError: Fatal exception in the data production loop: signal only works in main thread
It is from
https://github.com/tensorflow/models/blob/master/official/recommendation/data_pipeline.py
class BaseDataConstructor(threading.Thread): ... class BisectionDataConstructor(BaseDataConstructor): def construct_lookup_variables(self): import pdb; pdb.set_trace() start_time = timeit.default_timer() def lookup_negative_items(self, negative_users, **kwargs): import pdb; pdb.set_trace() output = np.zeros(shape=negative_users.shape, dtype=rconst.ITEM_DTYPE)  1
https://bugs.python.org/issue13120 seems to suggest it's been fixed?

python fabric run(command) the command is escaped ' change to \'?
My command
command = /home/andy/Documents/python_project/ebaysdk/bin/python3 u /home/andy/Documents/python_project/ebaysdk/myprogram/run_collectiondata_a.py "[('CCIYU', 'EBAYMOTOR', 1371602535, 20954)]
i use Python Fabric to run this command
con.run('''%s''' % (command))
but have a error
Command: '/home/andy/Documents/python_project/ebaysdk/bin/python3 u /home/andy/Documents/python_project/ebaysdk/myprogram/run_collectiondata_a.py "[(\'CCIYU\', \'EBAYMOTOR\', 1371602535, 20954)]'
the ' is escaped to \'
how can i prohibite escaping？

Add dimensions to a tensor and duplicate values along the new axes
Suppose I have a 2D ndarray X with
X.shape == (m, n)
I'd like to add two more dimensions to X, while copying the values along these new axes. i.e. I want
new_X.shape == (m, n, k, l)
and for all i,j
new_X[i, j, :, :] = X[i, j]
What's the best way to achieve this?

Converting a numpy operation to output of tensorflow layer
I am trying to convert a numpy layer using tensorflow and keras
# output from model op_from_model = <tf.Tensor '1_conv_1x1_parts/BiasAdd:0' shape=(?, 64, 64, 16) dtype=float32> # Numpy style  from scipy.ndimage import gaussian_filter, maximum_filter import numpy as np lst = np.zeros([16,3]) for i in range(maps.shape[1]): _map = maps[:,:,i] _map = gaussian_filter(_map, sigma=0.3) _nmsPeaks = non_max_supression(_map, windowSize=3, threshold=1e6) y, x = np.where(_nmsPeaks == _nmsPeaks.max()) if len(x) > 0 and len(y) > 0: lst[:,i] = [int(x[0]), int(y[0]), _nmsPeaks[y[0], x[0]]] def non_max_supression(map, windowSize, threshold): under_th_indices = plain < threshold plain[under_th_indices] = 0 return plain * (plain == maximum_filter(plain, footprint=np.ones((windowSize, windowSize)))) #TF layer style # adapted from here https://stackoverflow.com/questions/52012657/howtomakea2dgaussianfilterintensorflow from keras import backend as K import tensorflow as tf def gaussian_kernel(size: int, mean: float, std: float): d = tf.distributions.Normal(mean, std) vals = d.prob(tf.range(start = size, limit = size + 1, dtype = tf.float32)) gauss_kernel = tf.einsum('i,j>ij', vals, vals) return gauss_kernel / tf.reduce_sum(gauss_kernel) gauss_kernel = gaussian_kernel(5, 0.44, 0.5) # have to set correct params here gauss_kernel = gauss_kernel[:, :, tf.newaxis, tf.newaxis] filt_op = tf.nn.conv2d(np.expand_dims(np.expand_dims(np.array(map[:,:,0] , dtype = np.float32), axis=0),axis=3), gauss_kernel, strides=[1, 1, 1, 1], padding="SAME") indices = tf.image.non_max_suppression(filt_op, flatten_scores, max_output_size=10, iou_threshold=0.3)
How can I get the lst from the filtered indices as output of the model? I am using keras and TF.

Building a Recommendation System in TensorFlow
I am trying to implement the recommendation system described here https://cloud.google.com/solutions/machinelearning/recommendationsystemtensorflowapplytoanalyticsdata#example_of_generating_recommendations
By following the steps provided in the article, I was able to train the model. I am facing following two problems when I try to generate recommendation.
Problem  1
It works for client id less than 900. For most of the client id greater then 900, it gives following error.
$ python test.py 1000
Traceback (most recent call last): File "test.py", line 22, in <module> recommendations = generate_recommendations(user_idx, user_rated, row_factor, col_factor, k) File "/home/sijo_tk/tfrs/wals_ml_engine/trainer/model.py", line 349, in generate_recommendations user_f = row_factor[user_idx] IndexError: index 150629 is out of bounds for axis 0 with size 138493
I tried with two different models trained with 1M and 20M data set but both shows same error.
Here is my code for generating recommendation.
import sys import numpy as np from model import generate_recommendations import json import random client_id = int(sys.argv[1]) already_rated = [191,198] k = 5 user_map = np.load("model/user.npy") item_map = np.load("model/item.npy") row_factor = np.load("model/row.npy") col_factor = np.load("model/col.npy") user_idx = np.searchsorted(user_map, client_id) user_rated = [np.searchsorted(item_map, i) for i in already_rated] recommendations = article_recommendations (user_idx, user_rated, row_factor, col_factor, k) article_recommendations = [item_map[i] for i in recommendations] print(article_recommendations)
Please check this code and correct me if I am doing something wrong.
Problem 2
When I try client id less than 900, the model gives some recommended items, but most of the item id are not found in rating.dat or rating.csv files. Why this model giving item as recommendation which are not there in the training data set?

finding the value of individual items in an items list after discount was applied on the sum
I'm working on ordering system, and this is the problem
finding the value of individual items in an items list after discount was applied on the sum of all .
So assuming the following base item prices
Item_1 = 2 $ Item_2 = 4.5 $ Item_3 = 8.31 $
And applying a multiplier per item
Item_1 *= 3 Item_2 *= 2 Item_3 *= 4
And after the multiplier is applied on individuals, sum them to get the total
Total = Item1 + Item2 + Item3
Now there is a discount involved 1,6$ off from Total.
Total = 1.6;
How can I find the item price after the discount was applied.

How to group multiple parcels at one using PHP
I need a formula wich can help me to group multiple parcels at one.
I have a Parcel Object like this one :
<?php class Parcel { function __construct($length,$width,$height,$weight) { $this>length=$length; $this>width=$width; $this>height=$height; $this>weight=$weight; } private $length; private $width; private $height; private $weight; public function getParcelDetails() { echo "length=".$this>length."<br>"; echo "width =".$this>width."<br>"; echo "height=".$this>height."<br>"; echo "weight=".$this>weight ."<br>"; } public static function mergeParcels($parcels){ $new_parcel_length=0; $new_parcel_width=0; $new_parcel_height=0; $new_parcel_weight=0; foreach ($parcels as $key => $parcel) { # What is the formula that can create a new parcel which is enable to contain the parcels $parcels ? # The weight will be just additionned $new_parcel_weight+=$parcel>$weight; } $new_parcel= new static($new_parcel_length,$new_parcel_width,$new_parcel_height,$new_parcel_weight); return $new_parcel; } }
The goal is to merge to parcels into one, so in the main script I'll have something like this :
$parcel1=new Parcel(10,10,10,1); $parcel2=new Parcel(5,5,5,1); //$parcel1>getParcelDetails(); //$parcel2>getParcelDetails(); $new_parcel=Parcel::mergeParcels([$parcel1,$parcel2]); $new_parcel>getParcelDetails();
This picture can demonstrate the problem :
Please note that the problem is when i have multiple parcels where dimensions are not equals.
If the dimensions are equals, i can just add them to each other, but i don't really have a solution when dimensions are not the same.

Mixing function for non power of 2 integer intervals
I'm looking for a mixing function that given an integer from an interval <0, n) returns a randomlooking integer from the same interval. The interval size n will typically be a composite non power of 2 number. I need the function to be one to one. It can only use O(1) memory, O(1) time is strongly preferred. I'm not too concerned about randomness of the output, but visually it should look random enough (see next paragraph).
I want to use this function as a pixel shuffling step in a realtimeish renderer to select the order in which pixels are rendered (The output will be displayed after a fixed time and if it's not done yet this gives me a noisy but fast partial preview). Interval size n will be the number of pixels in the render (n = 1920*1080 = 2073600 would be a typical value). The function must be one to one so that I can be sure that every pixel is rendered exactly once when finished.
I've looked at the reversible building blocks used by hash prospector, but these are mostly specific to power of 2 ranges.
The only other method I could think of is multiply by large prime, but it doesn't give particularly nice random looking outputs.
What are some other options here?