Categories
Mastering Development

skip key and its value if key is empty in laravel [closed]

I am trying to skip key and it’s value if empty. Following example key f is empty and I want to remove that. $array1 = ["a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>5, "f"=>[], "i"=>0]; Expected array in laravel array ‘a’ => int 1 ‘b’ => int 2 ‘c’ => int 3 ‘d’ => int 4 ‘e’ => […]

Categories
Mastering Development

Split dataframe with all values in one row

I got the following dataframe which is created dynamically but saves all the relevant values into one row: df +—————-+—————-+—————-+—————-+ | 1 | 2 | 3 | 4 | +—————-+—————-+—————-+—————-+ | a1, b1, c1, d1 | a2, b2, c2, d2 | a3, b3, c3, d3 | a4, b4, c4, d4 | +—————-+—————-+—————-+—————-+ I need to […]

Categories
Mastering Development

minimization Converging to negative infinity despite constraints

I have the following optimization problem: from scipy import optimize import numpy as np def net_profit(x): return -(x[0] / (x[1] + x[2] + x[3]) * 365 * \ (x[4] – (x[5] + x[6])) * x[7] + \ x[8] * 12 – x[9] * 12) c0 = {‘type’: ‘ineq’, ‘fun’: lambda x: x[0]} c1 = {‘type’: […]

Categories
Mastering Development

How to prettify JSON.stringify() partially?

Users can download JSON files from our application, which I want to prettify for easier debugging than if all is in one line. However this increases the file size by nearly 40% even if the indentation is just a single tab or space. As a compromise, I want to exclude all values with e.g. the […]

Categories
CMS Mastering Development

Create a New Entry with Fields Populated from an Existing Entry Table

I am still learning how to work with craft on the back end but so far I can see it is a very powerful platform! I was wondering if there is a way that within an existing entry channel say "foo" I have an entry comprised of a table made up of multiple numerical values […]

Categories
Mastering Development

Overlapping text on top of geom_bar in ggplot2

I have made a barplot similar to the one below using ggplot2. I cannot get the percentages on top of the bars to be centered and not overlapping of other bars and numbers. Sample code is below. library(tidyverse) cat1=c("cat1","cat1","cat1","cat1","cat1","cat1","cat1","cat1","cat1","cat1","cat1","cat1", "cat2","cat2","cat2","cat2","cat2","cat2","cat2","cat2","cat2","cat2","cat2","cat2", "cat3","cat3","cat3","cat3","cat3","cat3","cat3","cat3","cat3","cat3","cat3","cat3", "cat4","cat4","cat4","cat4","cat4","cat4","cat4","cat4","cat4","cat4","cat4","cat4") cat2=c("c1","c2","c3","c4","c5","c6","c7","c8","c9","c10","c11","c12", "c1","c2","c3","c4","c5","c6","c7","c8","c9","c10","c11","c12", "c1","c2","c3","c4","c5","c6","c7","c8","c9","c10","c11","c12", "c1","c2","c3","c4","c5","c6","c7","c8","c9","c10","c11","c12") count1=round(rnorm(48,10)) fakeperc=rnorm(48,9) df1=cbind(count1,fakeperc) df2=cbind(cat1,cat2) finaldf=as.data.frame(cbind(df1,df2)) finaldf$cat1=as.factor(finaldf$cat1) finaldf$fakeperc=as.numeric(finaldf$fakeperc) #finaldf$cat1=factor(finaldf$cat1,levels = […]

Categories
Mastering Development

Flatten nested object/array in javascript

I’m new to Javascript and I have nested objects and arrays that I would like to flatten. I have… [{ a: 2, b: [{ c: 3, d: [{e: 4, f: 5}, {e: 5,f: 6}]}, { c: 4, d: [{e: 7, f: 8}]} ] }] and would like… [{a:2,c:3,e:4,f:5}, {a:2,c:3,e:5,f:6}, {a:2,c:4,e:7,f:8}] I’ve tried to adapt the […]

Categories
Mastering Development

Flatten nested array in javascript

I have a nested array that I would like to flatten. I have… [{ a: 2, b: [{ c: 3, d: [ { e: 4, f: 5 }, { e: 5, f: 6 } ] c:4, d: [ { e:7, f:8 } ] }] }] and would like… [ {a:2,c:3,e:4,f:5}, {a:2,c:3,e:5,f:6}, {a:2,c:4,e:7,f:8} ] I’ve tried […]

Categories
Mastering Development

Setting up an arbitrage strategy in R by solving system of inequalities subject to an equality constraint

I am trying to construct an arbitrage portfolio x such that Sx = 0 and Ax>=0, where A is the payoff matrix at t=1 and S is the price at t=0. I was not able to do it manually, so I tried using functions contained in the limSolve and lpSolve packages in R with no […]

Categories
Mastering Development

Plots of Conditional Multivariate KDE is not “smooth” as expected

I am trying to plot the PDF, CDF and Log CDF of a Conditional Multivariate KDE using Statsmodel, but the output is not what as I expect it to be: import statsmodels.api as sm nobs = 1000 c1 = np.random.normal(size=(nobs,1)) c2 = np.random.normal(2,1,size=(nobs,1)) c3 = np.random.normal(3,2,size=(nobs,1)) kde = sm.nonparametric.KDEMultivariateConditional(endog=[c1],exog=[c2,c3], dep_type=’c’, indep_type=’cc’, bw=’normal_reference’) fig = plt.figure(figsize=(15, […]