arrays

Setting an array element with a sequence.The requested array has an inhomogeneous shape after1dimensions.The detected shapewas(18,)+inhomogeneouspart

Setting an array element with a sequence.The requested array has an inhomogeneous shape after1dimensions.The detected shapewas(18,)+inhomogeneouspart Question: I’m trying to do a scatterplot between this 2 variables, but it gives me this error. ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was …

Total answers: 1

Python, let user define list variable

Python, let user define list variable Question: Trying to enable a user to input a mixed list in the correct format, ie with square brackets and commas already separating values. Using the input() function saves the entire input as a string. Using list() around this, just makes every character of the string a separate part …

Total answers: 1

np.piecewise generates incorrect values for integer array

np.piecewise generates incorrect values for integer array Question: I have a numpy piecewise function defined as def function(x): return np.piecewise(x, [x <= 1, x > 1], [lambda x: 1/2*np.sin((x-1)**2), lambda x:-1/2*np.sin((x-1)**2)]) I have no idea why this function is returning incorrect values for various x-values. In particular, running the following X = np.array([0,2.1]) Y = …

Total answers: 1

Reshape a 3d array to a 2d array with leading points

Reshape a 3d array to a 2d array with leading points Question: I want to reshape this array (Python) [[[0, 1, 2], [3, 4, 5], [6, 7, 8]], [[0, 1, 2], [3, 4, 5], [6, 7, 8]], [[0, 1, 2], [3, 4, 5], [6, 7, 8]]] To this: [ [0,0,0], [1,1,1], [2,2,2], [3,3,3], [4,4,4], [5,5,5], …

Total answers: 3

how to get modulus difference of values of two json objects in python

how to get modulus difference of values of two json objects in python Question: I have two JSON arrays , I need to get the modulus difference of the JSON object keys. My array list can have 1000s of elements. How to calculate it efficiently? Is there a way to do it parallelly without using …

Total answers: 1

Sort a string in the list alphabetacaly

Sort a string in the list alphabetacaly Question: i have the following list: strs = ["tea","tea","tan","ate","nat","bat"] i want to sort the strings in that list to be like that: strs = ["aet","aet","ant","aet","ant","abt"] how i can do this ? Thanks Asked By: Yussef Raouf Abdelmisih || Source Answers: out = [] for val in strs: out.append("".join(sorted(list(val)))) …

Total answers: 2

How to slice and calculate the pearson correlation coefficient between one big and small array with "overlapping" windows arrays

How to slice and calculate the pearson correlation coefficient between one big and small array with "overlapping" windows arrays Question: Suppose I have two very simple arrays with numpy: import numpy as np reference=np.array([0,1,2,3,0,0,0,7,8,9,10]) probe=np.zeros(3) I would like to find which slice of array reference has the highest pearson’s correlation coefficient with array probe. To …

Total answers: 1