all input arrays must have the same dimensions  python using append
import numpy as np
x = [1,2,3,4] y = [[5,6,7,8],[9,0,1,2]]
j = np.append(x,y,axis=0)
Traceback (most recent call last): File "", line 1, in File "C:\Python27\lib\sitepackages\numpy\lib\function_base.py", line 5147, in append return concatenate((arr, values), axis=axis) ValueError: all the input arrays must have same number of dimensions
See also questions close to this topic

InterpolatedUnivariateSpline and ax.fill_between yield unexpected result (filling wrong area) with low Yvalues
I have a function that is supposed to take some raw data, plot it onto a canvas and then fill the area between the baseline and a predefined peak, which works well for high Yvalues but gives the inverse result when using low Yvalues. My question is then twofold:
 Why does this occur?
 What is a robust way to fix this issue (I tried multiplying all Yvalues by 1E6 and, performing the InterpolatedUnivariateSpline fit and then dividing the returning fit by 1E6 again but there must be a better way to fix this).
Snippet:
X = [16.08278,16.090878,16.098978,16.107077,16.115177,16.123279,16.13138,16.139482,16.147586,16.155689,16.163793,16.171899,16.180004,16.18811,16.196218,16.204325,16.212433,16.220543,16.228652,16.236762,16.244874,16.252985,16.261097,16.269211,16.277324,16.285439,16.293554,16.30167,16.309786,16.317904,16.326021,16.334139,16.342259,16.350379,16.358499,16.366621,16.374742] Y = [1.496555,1.766111,2.074339,2.426317,2.825952,3.274024,3.764088,4.288722,4.839724,5.406741,5.978055,6.536869,7.064041,7.540824,7.948076,8.267242,8.48543,8.596198,8.598762,8.492928,8.279867,7.962899,7.55062,7.059239,6.508092,5.91964,5.318298,4.7234,4.148229,3.602356,3.094568,2.635609,2.231337,1.882143,1.58295,1.328678,1.113859] Y2 = [1496555,1766111,2074339,2426317,2825952,3274024,3764088,4288722,4839724,5406741,5978055,6536869,7064041,7540824,7948076,8267242,8485430,8596198,8598762,8492928,8279867,7962899,7550620,7059239,6508092,5919640,5318298,4723400,4148229,3602356,3094568,2635609,2231337,1882143,1582950,1328678,1113859] # Toggle low vs high Yvalues #Y = Y2 import matplotlib.pyplot as plt import numpy as np from scipy.interpolate import InterpolatedUnivariateSpline fig = plt.figure(figsize=(8, 6)) ax = fig.add_subplot(111) plt.plot(X, Y, 'b') plt.legend(['Raw Data'], loc='best') plt.xlabel("Retention Time [m]") plt.ylabel("Intensity [au]") newTime = np.linspace(X[0], X[1], len(X)) f = InterpolatedUnivariateSpline(X, Y) newIntensity = f(newTime) ax.fill_between(X, newTime, newIntensity, alpha=0.5) plt.show(fig)
This yields the following figures:
This is what I would expect (and occurs with high Yvalues).

idiom for getting contiguous copies
In the help of numpy.broadcstarray, an idiom is introduced. However, the idiom give exactly the same output as original command. Waht is the meaning of "getting contiguous copies instead of noncontiguous views."?
https://docs.scipy.org/doc/numpy/reference/generated/numpy.broadcast_arrays.html
x = np.array([[1,2,3]]) y = np.array([[1],[2],[3]]) np.broadcast_arrays(x, y) [array([[1, 2, 3], [1, 2, 3], [1, 2, 3]]), array([[1, 1, 1], [2, 2, 2], [3, 3, 3]])]
Here is a useful idiom for getting contiguous copies instead of noncontiguous views.
[np.array(a) for a in np.broadcast_arrays(x, y)] [array([[1, 2, 3], [1, 2, 3], [1, 2, 3]]), array([[1, 1, 1], [2, 2, 2], [3, 3, 3]])]

TensorFlow and word embeddings  TypeError: unhashable type: 'numpy.ndarray'
I wish to modify the code at http://www.brightideasinanalytics.com/rnnpretrainedwordvectors/, which is about predicting the next word, to have code that predicts answers to questions.
Here is an excerpt of the code I'm having trouble with:
import tensorflow.contrib as ct def NHIDDEN(): return 1 g = tf.Graph() tf.reset_default_graph() with g.as_default(): # lines 97104 of original code # RNN output node weights and biases weights = { 'out': tf.Variable(tf.random_normal([NHIDDEN(), embedding_dim])) } biases = { 'out': tf.Variable(tf.random_normal([embedding_dim])) } with tf.name_scope("embedding"): W = tf.Variable(tf.constant(0.0, shape=[vocab_size, embedding_dim]), trainable=False, name="W") embedding_placeholder = tf.placeholder(tf.float32, [vocab_size, embedding_dim]) embedding_init = W.assign(embedding_placeholder) preimage = tf.nn.embedding_lookup(W, x2) # lines 107119 of original # reshape input data x_unstack = tf.unstack(preimage) # create RNN cells rnn_cell = ct.rnn.MultiRNNCell([ct.rnn.BasicLSTMCell(NHIDDEN()), ct.rnn.BasicLSTMCell(NHIDDEN())]) outputs, states = ct.rnn.static_rnn(rnn_cell, x_unstack, dtype=tf.float32) # capture only the last output pred = tf.matmul(outputs[1], weights['out']) + biases['out'] # Create loss function and optimizer cost = tf.reduce_mean(tf.nn.l2_loss(predy)) optimizer = tf.train.AdamOptimizer(learning_rate=0.001).minimize(cost) # lines 130, 134 and 135 of original step = 0 acc_total = 0 loss_total = 0 with tf.Session(graph = g) as sess: # lines 138, 160, 162, 175, 178 and 182 of original while step < 1: # training_iters: _,loss, pred_ = sess.run([optimizer, cost, pred], feed_dict = {x: tf.nn.embedding_lookup(W, x2), y: tf.nn.embedding_lookup(W, y)}) loss_total += loss print("loss = " + "{:.6f}".format(loss_total)) step += 1 print ("Finished Optimization")
The error I get is:
 TypeError Traceback (most recent call last) <ipythoninput77a72d8d4f100> in <module>() 42 while step < 1: # training_iters: 43 _,loss, pred_ = sess.run([optimizer, cost, pred], feed_dict = > 44 {x: tf.nn.embedding_lookup(W, x2), y: tf.nn.embedding_lookup(W, y)}) 45 loss_total += loss 46 print("loss = " + "{:.6f}".format(loss_total)) TypeError: unhashable type: 'numpy.ndarray'
How do I fix the code? Is it because of
unstack
ing?Additional context:
x2
andy
are assigned the return value ofnp.array(list(vocab_processor.transform([s])))
wheres
is a string (by passing different strings).embedding_dim
,vocab_size
andW
are computed using the code at https://ireneli.eu/2017/01/17/tensorflow07wordembeddings2loadingpretrainedvectors/. 
compare 3 different arrays and if data matches add to new array
I have three different arrays. First array
$years = [2015,2016,2017,2018];
Second array
$users = ["a","b","c"];
Third array
$data = [ {"year":2015,"user":"a","amount":100}, {"year":2016,"user":"a","amount":90}, {"year":2017,"user":"b","amount":70}, {"year":2018,"user":"c","amount":80} ];
Now i want to compare all those arrays and get the data for each user for each year i.e if a user does not exists in particular year then 0 should be inserted in that place in below format
Required output :
{"name":"a", "data":[100,90,0,0]}, {"name":"b", "data":[0,0,70,0]}, {"name":"c", "data":[0,0,0,80]}
Any help would greatly appreciated,
My code so far is
foreach($yeararray as $year) { foreach($usersarray as $user) { if($user == $data["user"]) && ($year == $data["year"])) { array_append($newarray, $user); } else { array_push($newarray, $user); } } }
but it is not working i think my code is somewhere wrong, Please help!

Append string at the beginning
I have a pandas Series of strings and I want to append this strings at the beginning of it with zeros.
for example I have this
123456
and I want to have this00000123456
. Not all the strings are equal size(length) and each string's size must be 11.I tried this code:
x = [6, 7, 8, 9, 10] for i in range(len(x)): if x[i] == df['ID'].str.len(): df['ID'].join((11i)*'0')
and getting this error:
The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Can anyone help me?

Popup function in jquery
Case: I'm appending different profiles with a picture, name, age and gender inside an htmlsection. (Think Tinder, but showing 10ish profiles at once.) I want a function that makes a popup with 'newInterests' printed out in a ptag, specific to each profile. If you click a button or if you click the profilepicture isnt that important.
I cant find any way to do this, maybe you guys have a solution? :) Thanks in advance!
Note: Appending the profiles work. I'm able to show pictures with names and such, I just can't find a way to implement a popup specific to each profile.
Note 2: let newInterests = profileInterests = profile.description; Prints out the variable. I just want it to be included in a popup.
HTML:
<section id="profileSection"> </section>
JS:
$("#showAllMenBtn").click(function(){ $("#profileSection").html(""); $(maleProfiles).each(function(index, profile){ let profileImg = $("<img>", {src:`${profile.imageSrc}`}); let newName = profileName = profile.name; let newAge = profileAge = profile.age; let newGender = profileGender = profile.gender; //let newInterests = profileInterests = profile.description; $("#profileSection").append(profileImg, newName, newAge, newGender); }) });
I get everything from a JSON module, which you can see here: