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

Distance matrix API output in XLM form to be transferred to a table
I have one origin, 3 destinations. I am trying to find the distance and the time taken to travel using google distance API.
I want to get the distance and the time to a table. how can i extract those using the output they give using python?
{'destination_addresses': ['153 Lower St, Badulla, Sri Lanka', 'Unnamed Road, Sri Lanka', 'Palahala, Sri Lanka'], 'origin_addresses': ['No: 36/6, Vishaka Rd, Bandarawela, Sri Lanka'], 'rows': [{'elements': [{'distance': {'text': '28.4 km', 'value': 28359}, 'duration': {'text': '6 hours 6 mins', 'value': 21978}, 'status': 'OK'}, {'distance': {'text': '170 km', 'value': 170497}, 'duration': {'text': '1 day 12 hours', 'value': 128067}, 'status': 'OK'}, {'distance': {'text': '166 km', 'value': 165565}, 'duration': {'text': '1 day 12 hours', 'value': 128690}, 'status': 'OK'}]}], 'status': 'OK'}

Flask SqlAlchemy returing json.decoder.JSONDecodeError
I was trying to query all row in SQLite DB from flask app using flasksqlalchemy. I trying to do the same with python 3.6.8.
def get(self): result = models.Template.query.all() model_data = [] for row in result: model_data.append({ "annotations": row.json_template, }) return jsonify({"data": model_data})
The line result = models.Template.query.all() is returing
json.decoder.JSONDecodeError json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 3 (char 2)
The contents in the database are (testing with a single row and single column)
json_template : [{'name': 'rect', 'x': 152230, 'y': 378, 'width': 1344, 'height': 354, 'AttrName': 'esf'}]
The json_template is defined in the models.Templates class as
json_template = app.db.Column(JSON, nullable=False)
Could someone please tell me the possible cause and solution? If I've missed out anything, over or underemphasized a specific point, let me know in the comments.

I am getting an error of "object arrays are not supported" when i am fitting the Dynamic Factor Model under statsmodels package
I'm trying to fit the dynamic factor model to my data for forecasting but I'm getting this error.
'dk'
is a dataframe of stock index time series data. I'm doing the following:dk_dfm = dk.loc['08Nov15':,'std_Volume':'std_IR'] mod = statsmodels.api.tsa.DynamicFactor(endog = dk_dfm, k_factors=1, factor_order=2, error_order=3)
till here it's getting processed.
dfm = mod.fit(method='newton', disp=False)
here i'm getting the error: 'object arrays are not supported'

Linear Regression showing error as Data must be 1D
Trying to run linear regression on the data and getting an error that 'Data must be 1dimensional'.
Sample data
Year ln_kar 1 4.65 2 5.63 3 6.63 4 2.33
import pandas as pd import numpy as np from sklearn.linear_model import LinearRegression data1= pd.read_excel('C:\\Users\\3004\\Desktop\\Vaibbhav\\data\\Agricultural cost and price state wise\\crop cost CACP.xlsx',2) x=data1['Year'] y=data1['ln_kar'] x1 = np.reshape(x,(1,1)) y1 = np.reshape(y,(1,1)) model = LinearRegression().fit(x1,y1) print('intercept: ',model.intercept_) print('slope: ',model.coef_)

Occupancy counter using python and opencv
I want to count the number of people in an image sitting in a class. I figured the best possible way might be to convert the image into a black and white image and zone out our regions of interest.
Here is the code:
import cv2 import numpy as np def roi(img, ver1, ver2, ver3, ver4): mask = np.zeros_like(img) for i in range(len(mask)): for j in range(len(mask[0])): mask[i][j] = 255 cv2.fillPoly(mask, ver1, 0) cv2.fillPoly(mask, ver2, 0) cv2.fillPoly(mask, ver3, 0) cv2.fillPoly(mask, ver4, 0) masked = cv2.bitwise_or(img, mask) return masked img = cv2.imread("university.jpg") img = cv2.resize(img, (0, 0), fx = 0.5, fy = 0.5) _, img = cv2.threshold(img, 100, 255, cv2.THRESH_BINARY) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) mat = np.array(gray) for i in range(len(mat)): for j in range(len(mat[0])): if mat[i][j] < 100: mat[i][j] = 0 else: mat[i][j] = 255 cv2.imshow('ff', mat) vert1 = np.array([[150, 240], [485, 240], [485, 310], [150, 310]]) vert2 = np.array([[0, 230], [70, 230], [70, 290], [0, 290]]) vert3 = np.array([[600, 235], [530, 235], [545, 275], [555, 290], [600, 290]]) vert4 = np.array([[0, 330], [600, 330], [600, 450], [0, 450]]) newImg = roi(mat, [vert1], [vert2], [vert3], [vert4]) cv2.imshow('out1', newImg)
and the output image is:
How can I proceed further and count the number of occupants in each zone?

could not reshape input array shape question
I tried to reshape the image array
original image shape is (224,224,3)trainImages = np.array([i[0] for i in train_datas]).reshape(1, IMG_SIZE, IMG_SIZE,3)
ValueError: cannot reshape array of size 502562816 into shape (224,224,3)
How should I reshape it when I want to get a (224,224,3)

For any given X, how many Y would I need to end up with Z amount of X by the end of function
I have two variables, attackers and defenders, I want to know, for any given defenders, how many attackers would I need to end up with X amount of attackers by the end of the battle?
Their battle is handled in a function that does this:
while(defenders > 0 && attackers > 0) { newDefenders = attackers  defenders * .1 newAttackers = defenders  attackers * .1 defenders = newDefenders attackers = newAttackers }
How could I compute this?

Find the number of quadruplets with GCD equal to 1
Given a sequence of numbers from 1 to N, we have to find the number of quadruplets such that their Greatest Common Divisor (GCD) is 1.
Constraints : N <= 10^5
Example : N=5. So the number of such quadruplets from {1,2,3,4,5} are :
 {1,2,3,4}
 {1,2,3,5}
 {1,2,4,5}
 {1,3,4,5}
 {2,3,4,5}
So the answer in this case is 5.

Find the element in virtually infinite list
I'm trying to solve this problem:
A list is initialized to
["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
, and then undergoes a series of operations. In each operation, the first element of the list is moved to the end of the list and duplicated. For example, in the first operation, the list becomes["Leonard", "Penny", "Rajesh", "Howard", "Sheldon", "Sheldon"]
(with"Sheldon"
being moved and duplicated); in the second operation, it becomes["Penny", "Rajesh", "Howard", "Sheldon", "Sheldon", "Leonard", "Leonard"]
(with "Leonard" being moved and duplicated); etc. Given a positive integer n, find the string that is moved and duplicated in the nth operation. [paraphrased from https://codeforces.com/problemset/problem/82/A]I've written a working solution, but it's too slow when n is huge:
l = ['Sheldon','Leonard','Penny','Rajesh','Howard'] n = int(input()) # taking input from user to print the name of the person # standing at that position for i in range(n): t = l.pop(0) l.append(t) l.append(t) #debug # print(l) print(t)
How can I do this faster?