Categories
Mastering Development

Fast way to remove array of specific row values from 2D numpy array

I have a 2D array like this: a = np.array([[25, 83, 18, 71], [75, 7, 0, 85], [25, 83, 18, 71], [25, 83, 18, 71], [75, 48, 8, 43], [ 7, 47, 96, 94], [ 7, 47, 96, 94], [56, 75, 50, 0], [19, 49, 92, 57], [52, 93, 58, 9]]) and I want to […]

Categories
Mastering Development

Object.keys(myObject) returns an arbitrary list of numbers, not expected value

This is a bit of a head-scratcher – and has been a source of pain for the past 3 hours. Here’s my code. const payloadBody = JSON.parse(gatewayEvent.body); console.log(payloadBody); console.log(gatewayEvent.body); console.log(payloadBody.paymentMethodId); console.log(payloadBody[‘paymentMethodId’]); console.log(Object.keys(payloadBody)); If I look at the CloudWatch logs for this (I am executing in Lambda), the line console.log(payloadBody) logs: { "customerId": "cus_REDACTED", "paymentMethodId": "pm_REDACTED", […]

Categories
Mastering Development

str.replace() doesn’t replace nor throw errors (python)

So I scraped a list of heights from a website, and I am trying to find an average of these heights in ft and in. My problems is that the str.replace() is not working here and I am not sure why. (It doesn’t give me any error messages) Any suggestions on how to fix this? […]

Categories
Mastering Development

Having a problem with input_shape on Conv1d Layer

I’m attempting to perform a sentiment classification using CNN. The error seems to be related to the input_shape parameters. The x data consists of arrays of integers created using tokenizer.texts_to_sequences. ? x_train.shape (4460, 20) ? x_trains.shape[0] array([ 49, 472, 4436, 843, 756, 659, 64, 8, 1328, 87, 123, 352, 1329, 148, 2996, 1330, 67, 58, […]

Categories
Mastering Development

correlation between groups in R

df <- data.frame(row.names = c(‘S.5.0U0′,’S.6.0U1′,’S.7.0U2′,’S.8.0U3’),vara=c(-1.2,15,8.5,0),varb=c(-29,29,2.6,5),var1=c(-0.5,1.5,58,0),var2=c(-2.09,-12,2.6,-0.75),var3 = c(0,0.056,-12,5.5)) > df vara varb var1 var2 var3 S.5.0U0 -1.2 -29.0 -0.5 -2.09 0 S.6.0U1 15.0 29.0 1.5 -12.00 0.056 S.7.0U2 8.5 2.6 58.0 2.60 -12 S.8.0U3 0.0 5.0 0.0 -0.75 5.5 I want to correlate vara with var1,var2,var3 and I want to correlate varb with var1,var2,var3. I tried […]

Categories
Mastering Development

Can I use regexp_replace or some equivalent to replace multiple values in a pyspark dataframe column with one line of code?

Can I use regexp_replace or some equivalent to replace multiple values in a pyspark dataframe column with one line of code? Here is the code to create my dataframe: from pyspark import SparkContext, SparkConf, SQLContext from datetime import datetime sc = SparkContext().getOrCreate() sqlContext = SQLContext(sc) data1 = [ (‘George’, datetime(2010, 3, 24, 3, 19, 58), […]

Categories
Mastering Development

Efficient neighbourhood search in numpy ndarray instead of nested conditional for loops

Although there are many instances of the question: "What is the numpy alternative to nested for loops", I was unable to fins a suitable answer for my case. Here it goes: I have a 3D numpy array with "0" background and other integers as foreground. I would like to find and store the foreground voxels […]

Categories
Mastering Development

Compare list of list with dictionary

My list of list is candidates= [[714, 1023, 768, 1078], [803, 938, 868, 995]] My dictionary is: main_dict = {(1561, 48, 1623, 105): [[[1592, 58]], [[1591, 59]], [[1585, 59]], [[1600, 58]]], (714, 1023, 768, 1078): [[[1, 5]], [[2, 6]], [[3, 3]], [[4, 3]]], (803, 938, 868, 995): [[[14, 5]], [[22, 64]], [[34, 31]], [[43, 32]]] […]

Categories
Mastering Development

my player wont collide with my wall class

I want to know why every time my player keeps falling off my wall class every time i step on it, every time i step on it it slowly starts sinking down. I am new to python and I am still learning can you please help me.every time I start the game the floor/wall will […]

Categories
Mastering Development

Regex to find multiple values between two words

I’m trying to retrieve multiple values between two words, delimiting a specific part of the text. The pattern is this: (^\d\d\d\d)\D+ I’ve tried a lot of regex, but I was not successful. Below is an example of an attempt that is not working, because it is only returning the first value. Livro[\s\S]*?(^\d\d\d\d)\D+[\s\S]*(?=em moeda corrente) The […]