I have the following array output which I'd like to merge:
004249512651280042495126512800424951265128
There are 3 seperate arrays there, which are outputting data from a database, which has these numbers populated. These are the arrays:
00424951265128
00424951265128
00424951265128
I've tried the array_merge function to merge the data but it doesn't seem to work, I still get the same output.
The array data comprises of the following numbers:
0
0
4249
5126
5128
The code I'm using is as follows:
$player_ids = get_post_meta($post_id,"sp_player", false);
$new_player_ids = array_merge($player_ids);
foreach ( $new_player_ids as $new_player_id ){
print_r ($new_player_id);
Is there another function I've not found yet? Am I doing something wrong here. I'm not sure why one array is being repeated more than once.
Actually guys - figured it out. I had the code within a loop hence it was multiplying the array 3 times.
Fixed it woohoo!!
Thanks for looking
Related
Here is the shape of my array
b = data[0].values
print(b.shape)
(5126, 4229)
I get this error when I run this code:
from impyute.imputation.cs import mice
# start the MICE training
a=mice(b)
Error:
ValueError: Expected 2D array, got 1D array instead:
array=[].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.
I am confused by this error message, any recommendations?
First, you must change your input data to a 2D array, so you must specify the number of features in your data using reshape function.
Please try to use b.reshape(5126, 4229), if not try to follow this example until you figure out the problem
I'm using this json content (I'm open to suggestions on better formatting here):
{"forwardingZones": [{"name": "corp.mycompany.com","dnsServers": ["192.168.0.1","192.168.0.2"]}]}
Note: we may add more items to this list as we scale out, both more IPs and more names, hence the "join(',')" in the end of the code below.
And I'm trying to loop through it to get this result:
corp.mycompany.com=192.168.0.1;192.168.0.2
Using this code:
forward_zones = node['DNS']['forward_zones'].each do |forwarded_zone|
forwarded_zone_name = forwarded_zone['name']
forwarded_zone_dns_servers = forwarded_zone['dns_servers'].join(';')
"#{forwarded_zone_name}=#{forwarded_zone_dns_servers}"
end.join(',')
This is the result that I get:
{"dnsServers"=>["192.168.0.1", "192.168.0.2"], "name"=>"corp.mycompany.com"}
What am i doing wrong...?
x.each returns x. You want x.map.
Scala beginner who is trying to store values obtains in a Scala foreach loop but failing miserably.
The basic foreach loop looks like this currently:
order.orderList.foreach((x: OrderRef) => {
val references = x.ref}))
When run this foreach loop will execute twice and return a reference each time. I'm trying to capture the reference value it returns on each run (so two references in either a list or array form so I can access these values later)
I'm really confused about how to go about doing this...
I attempted to retrieve and store the values as an array but when ran, the array list doesn't seem to hold any values.
This was my attempt:
val newArray = Array(order.orderList.foreach((x: OrderRef) => {
val references = x.ref
}))
println(newArray)
Any advice would be much appreciated. If there is a better way to achieve this, please share. Thanks
Use map instead of foreach
order.orderList.map((x: OrderRef) => {x.ref}))
Also val references = x.ref doesn't return anything. It create new local variable and assign value to it.
Agree with answer 1, and I believe the reason is below:
Return of 'foreach' or 'for' should be 'Unit', and 'map' is an with an changed type result like example below:
def map[B](f: (A) ⇒ B): Array[B]
Compare To for and foreach, the prototype should be like this
def foreach(f: (A) ⇒ Unit): Unit
So If you wanna to get an changed data which is maped from your source data, considering more about functions like map, flatMap, and these functions will traverse all datas like for and foreach(except with yield), but with return values.
I have a data frame DF which contains numerous variables. Each variable is present twice because I am conducting an analysis of "couples".
Among others, DF has a series of indicators of diversity :
DF$div1.1, DF$div2.1, .... , DF$divN.1, DF$div.1.2, ..., DF$divN.2
Similarly, it has a series of indicators of another characteristic:
DF$char1.1, DF$char2.1, .... , DF$charM.1, DF$char.1.2, ..., DF$charM.2
Here's a link to an example of DF: http://shorttext.com/5d90dd64
Each time the ".1", ".2" stand for the couple member considered.
My goal:
For each indicator divI and charJ, I want to create another variable DF$divchar that takes the value DF$divI.1 when DF$charJ.1>DF$charJ.2; and DF$divI.2 when DF$charJ.1<DF$charJ.2.
Here is the solution I came up with, it seems somehow very intricate and sometimes behaves in strange ways:
I created a series of binary variables that take the value one if DF$charJ.1>DF$charJ.2. The are stored under DF$CharMax.1.
Here's how I created it:
DF$CharMax.1 <- as.data.frame(
sapply(1:length(nam),
function(n)
as.numeric(DF[names(DF)==names.1[n]]
>DF[names(DF)==names.2[n]])
))
I created the function BinaryExtract:
BinaryExtract <- function(var1, var2, extract) {var1*extract +var2*(1-extract)}
I created the matrix NameFull that contains all the possible combinations of div and char, separated with "YY"
NameFull <- sapply(c("div1",...,"divN")
, function(nam) paste(nam, names(DF$YMax.1), sep="YY")
And then I create all my variables:
DF[, as.vector(NameFull)] <- lapply(as.vector(NameFull), function(e)
BinaryExtract(DF[,paste0(unlist(strsplit(e,"YY"))[1],".1")]
, DF[, paste0(unlist(strsplit(e,"YY"))[1],".1")]
, DF$charMax.1[unlist(strsplit(e,"YY"))[2]]))
My Problem
A. It looks like a very complicated solution for something that simple. What am I missing?
B. Moreover, when I print DF, just typing DF in the command window, I do not see the variables NameFull. They seem to appear with the names of char.
Here's what I get: http://shorttext.com/5d9102c
Similarly, I have tried to change all their names to get rid of the "YY" and it does not seem to work:
names(DF[, as.vector(NameFull)]) <- as.vector(c("div1",...,"divN"), sapply(, function(nam)
paste(nam, names(DF$YMax.1), sep=".")))
When I look at names(DF), I keep getting the old names with the "YY"
However, I do get a result if I explicitly call for them
> DF[,"divIYYcharJ"]
I would really appreciate any suggestion, comment and explanation. I am quite new to R ad was more used to Stata. I feel there is something deeply inefficient here. Thanks
Im trying to store values from radialspeed (a function from the phased array toolbox) into an array, but im getting errors:
Conversion to cell from double is not possible.
Error in modelCar (line 40)
Cell(1,T)= Rspeed;
^^Error Message
Cell = cell(1,12)
for T = 1:11
[POS,v] = step(H,T);
Rspeed = radialspeed(POS,v,[25; 25; 70],[0; 0; 0]);
typecast(Rspeed,'uint16');
Cell(1,T)= Rspeed;
%%Rspeed = Vel.Radspeed(:,T);
disp(Rspeed);
end
^^^Excerpt of the code im using.
Another question any tips to plot a graph continuously while in the loop, the draw now function doesn't seem to work
Thank you.
You should not use Cell as a variable since cell is reserved keyword in MATLAB. Though using Cell will pose no problems, but a simple typing mistake can inject errors into your code. You may use myCell, R_cell etc.
By writing, Cell(1,T)= Rspeed you are trying to assign Rspeed of type double to a cell datatype. You should write Cell{1,T}=Rspeed or Cell{T}=Rspeed. You can also visualize your output for each iteration as follows:
Replace disp(Rspeed) by:
hold on;scatter(T,Rspeed,'ro');
pause(0.001);
1st question: Cell(1,T) will return a cell so you need to change your code to Cell{T}= Rspeed;.
2nd question: recall plot is a possible solution if speed is not a main concern.