All Questions
Tagged with python-3.x arrays
3,197
questions
-1votes
0answers
10views
Ragged nested array need to be converted to array of float
I have a ragged nested array with class 'numpy.ndarray' which I want to convert it to a string of float which I already try to use np.asfarray to change it. the problem is that, my Jupyter Notebook ...
0votes
0answers
7views
How to combine and handle data list in dictionary python
I have a big problem. This is my data.The data structure looks like this. It include metric_name, date_time and data of date_time in metric_name.
{
"metric_name 1":{
"date_time 1&...
-2votes
1answer
16views
Python array conditions
I wanna know how do I initialize a 2d array where the first row will have all even from 0-10, and 2nd row will have all odd from 11-20, so and so until in column 10 we will have 91-100 of all odd?
...
0votes
3answers
23views
multi-dimensional dictionary to dataframe python
dict_abc = {'A': [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
'B': [[4, 4, 4], [2, 2, 3],],
'C': [[4, 6, 0]]
}
I would like to convert this to a dataframe in the form
| x | y | z |
...
-3votes
0answers
31views
Load the data using numpy [closed]
I am having an error which says - "axis 2 is out of bounds for array of dimension 1"
in the below code
data = np.rollaxis(np.load('data.npy'),2,5)
data[:,:,:,:,[0,1,2]] = data[:,:,:,:,[...
0votes
1answer
31views
Finding the index of an element that divide the array to two equal sums
take an array and find an index i where the sum of the integers to the left of i is equal to the sum of the integers to the right of i. If there is no index that would make this happen, return -1.
Why ...
0votes
0answers
29views
Randomize questions and options together
{
"question": [
"The person signing cremation authorization, giving permission for the cremation to take place?",
"Receptacle used to transport and house the body ...
1vote
1answer
24views
Arranging a list based on the distance of its elements from a given value
Let's assume we have a list like the following
[2.3, 1.02, 1.99, 0.99, 0.089, 0, 1.1, -1.1, -2.1]
We want to arrange the elements of this list based on their distance from target value equal to 1 in ...
0votes
0answers
35views
Python - Numba produces syntax error for For-Loop
I have the following code in which I create two 1D NumPy arrays (f0src and f1src) and then create a two for loop for calculate some function with every combination of f0src and f1src arrays. I pre-...
1vote
1answer
23views
How to sort two array in the same manner?
I have two lists and fancy to sort them according to the first one. I get indexes how the first array s was sorted. How to apply the same order/the list of indexes to the s2, please?
s = [2, 3, 1, 4, ...
0votes
3answers
35views
Why is this function overwriting my list?
I just started on a project of making different types of sorting algorithms for fun, but I just can't figure out why this function is overwriting a variable.
I have a main file:
import bubble
test = [...
-1votes
1answer
21views
Why is my object being duplicated when I try to add it to an array?
I'm using the following to loop through some returned SQL data that has two fields.
cont = []
datarow = {}
for x in result:
input = x[0]
response = x[1]
datarow['input'] = input
...
-5votes
1answer
38views
How do I generate a random number sequence in python
Is there any way to make a numerical sequence in python randomly but with a predefined range?
Example:
number = random range( 1,10 )
number = 6
Output:
Example 1: [1,2,3,4,5,6]
I would like to make ...
0votes
1answer
26views
Error with array() function in python-3.x
im new in python.
part of my code is:
def _checksum(self, data):
if sum(len(i) for i in data) & 1:
data.append('\0')
**words = array('h', ''.join(data))**
checksum = 0
...
1vote
1answer
31views
How do I reshape a NumPy multi dimensional array to another array with the same dimensions, but different shape?
I have a NumPy multi dimensional array of shape (1,76,76,255). I want to reshape it to another multidimensional array of shape (1,255,76,76). It’s still a 4D array, but I need to change the data ...
1vote
1answer
29views
Strange comportement of list/array
I want to understand why the comportement of my array is like that:
import numpy as np
import math
n=10
P=np.array([[0]*n]*n)
P[2][2]=1 #It works as I want
for i in range(n):
for j in range(n):
...
0votes
0answers
31views
How can I fix IndexError: invalid index to scalar variable
I am trying to convert cartesian to spherical coordinates and following is my code. I am getting the error IndexError: invalid index to scalar variable when it's trying to calculate ph = math.atan2(-...
1vote
1answer
38views
How to get all combination for a given sum with a given number of elements
I have a list of list of floats like this
numbers = [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9]
I want a python code that can generate all possible combinations for given sum (=1) and a given number of ...
1vote
1answer
32views
How can I calculate conditional counting for each entries of a tuple?
def Trigger(V1, P_T, N1, N2): # N1 = N_W # N2 = N_A
V = np.transpose(V1[:N1])
c = 0
for l in range(N2): # over number of antennas
if ( sum( (np.array(V[l]) >= ...
0votes
2answers
38views
how to loop with multiple index in Python
I have to write a loop which is very simple in languages like java and c.
for (int i = 0; i <arr.length()-1; i++) {
for (int j = i+1; j <arr.length(); j++) {
//process
}
}
But I can'...
-1votes
1answer
26views
caluculating error or parents error in python?
a = 1200
b = 2200
c = 28276
t = 7
de = 7
dx = 12
func = (a*t)de+(b*t)dx-c
print(func)
but after compiling this, some error occurred.
File "", line 9
func = (at)de+(bt)dx-c
^
SyntaxError: ...
0votes
0answers
22views
NumpyArray => IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed
I'm new to python and I'm trying to use a code I found on a paper to analyze time series data (https://github.com/BML-cbnu/TRACS). The thing is I'm getting troubles to run that code. I'm giving to ...
0votes
2answers
48views
How to append N number of an array to the end of another array
I have an array of size 99 columns by 100 rows but want to add the last row of the 2D array to the end of the array N times. My current code to do this is:
import numpy
array = numpy .concatenate((l,...
0votes
0answers
12views
I'm getting an error "PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x000001FFA78D10E0>" when converting bytes to img
I am attempting to merge 2-byte arrays together and convert the bytes all together back into an image. However, I keep getting the issue "open raise UnidentifiedImageError( PIL....
0votes
1answer
35views
Resizing list from a 2D array
I came across a problem when trying to do the resize as follow:
I am having a 2D array after processing data and now I want to resize the data, with each row ignoring the first 5 items.
What I am ...
1vote
1answer
32views
download image from google cloud storage and send it in a request fails
I am trying to write a code to first download a dicom image from google cloud storage in python and send it over to a nodejs server in a post request. here is the code snippet
from google.cloud import ...
-1votes
0answers
28views
Making numpy array creation faster
I am working on ROS. In a python program, I am subscribing to a topic which give a large array of integer of approx size 1 million. Getting this data from topic into a numpy array takes a huge time (...
-3votes
1answer
28views
Error in my Python guessing game. errors appearing
I made a Guessing game in python in which there will be a String That you will have to guess and input it. You get 3 tries and if failed a printed statement will show up saying "Game lost", ...
0votes
1answer
18views
Python: how to split a nested numpy array and use each in encryption method
I have a numpy array which looks like this for example but a lot larger.
[[1, 3, 6, 2, 6]
[11, 4, 3, 6, 3]
[4, 4, 1, 5, 8]]
What I would like to do is get each nested array from the numpy array and ...
1vote
1answer
41views
Why is zero-terminated bytes is not recommended in numpy.array for string?
As per NumPy offical doc:
Array-protocol type strings (see The Array Interface)
...
'S', 'a' zero-terminated bytes (not recommended)
'U' Unicode string
...
For backward compatibility with Python 2 ...
-3votes
1answer
45views
Python: Split numpy array by index
So I have a numpy array with lots of nested arrays inside. Each nested array contains lots of data e.g.
[[ 0.27048764 -0.29546663 -0.7458692 ... -4.9339285 -5.6773453
-6.092227 ]
[ 0.901569 0....
0votes
2answers
39views
How to compare two numpy arrays with multiple condition
I have 2 NumPy arrays like the below
array_1 = np.array([1.2, 2.3, -1.0, -0.5])
array_2 = np.array([-0.5, 1.3, 2.5, -0.9])
We can do the element-wise simple arithmetic calculation (addition, ...
0votes
1answer
26views
Split Numpy array by column value, while keeping track of row indexs
Say I have a numpy array:
Y.shape = (n, 3)
where n is the amount of rows in the numpy array.
I split Y based on the values of the second column by following this thread:
distances = [Y[Y[:, 1] == k] ...
0votes
0answers
17views
Python code changes 2-D array incorrectly, how to fix? [duplicate]
I want my code to return a square grid full of "x"'s and a single "I" at location (3,2), as seen bellow:
xxxxx
xxxxx
xxixx
xxxxx
xxxxx
I wrote the code bellow originally
...
-2votes
0answers
34views
check string listin python
I have list in python which is contains string like this :
['return x + y print("hello")', 'return x - y', 'return x * y', 'return x / y']
i want to check this list and return True if ...
0votes
0answers
14views
asyncpg.exceptions._base.InterfaceError: the server expects 1 argument for this query, 2 were passed
I want to delete element from array in this code
async def delete_title(self, telegram_id, array):
sql = "UPDATE Users SET title_id_list=(SELECT array(SELECT unnest(title_id_list) EXCEPT ...
0votes
0answers
18views
Sharing Large Arrays in order to let pool.mp work with numpy.array for parallel numerical caculations
I try to learn parallel computer in python using multiprocessing for numerical calculations. In order to share numpy.array, I found following example from https://research.wmz.ninja/articles/2018/03/...
0votes
1answer
46views
Using np.array to append into a 2D np.array
I have to read data from a file and create a new 1D np.array for each of my variables (V and T):
V = np.array([])
T = np.array([])
for ii in range(len(velocity)):
if (velocity[ii] !=-9....
0votes
0answers
19views
Removing the common elements between two lists from the first list not intentionally [duplicate]
I am trying to get tow lists one with all IDs and one with particular IDs but at the end of the loop the common item from the first enter image description herelist is removed by it self :
0votes
2answers
29views
I am getting error in code in taking input and append it to array
You are given N sticks, where the length of each stick is a positive integer. A cut operation is performed on the sticks such that all of them are reduced by the length of the smallest stick.
Given ...
0votes
0answers
27views
Peak detection in 2D array for realtime processing
I have a 10x510 numpy array. It consist of readings from a real-time sensor. I want to find the peak of all rows individually and create a 2d array telling the peak index in each row. Each row can ...
0votes
1answer
26views
Why do I have a RunTime error for my Python code?
I am doing the Hackerrank basic Python programming challenges. This one is called Mini-Max Sum* and the link for the problem is: https://www.hackerrank.com/challenges/one-week-preparation-kit-mini-max-...
-1votes
1answer
30views
python program to get n unique sequence number within a range
the input is the range and total number needed.
consider input range is (0,1)
if the total number needed is 10.Then output should be an array containing 10 values between 0 to 1. including 0 and 1.
if ...
0votes
2answers
31views
How do I manipulate my string to insert individual characters of another string in Python?
I want to insert each character from one string, let's call it string A, into every other slot in another string, let's call it string B.
So, for example:
stringA = "abcde"
stringB = "...
0votes
4answers
28views
I want to compare list of two cities and if list B cities are not present in list A then should append in list A using python
A=['mumbai','delhi','jaipur']
B=['mumbai','kolkata','pune']
I want to compare list A and list B and if list B cities are not in list A then we should able to append those cities in list A
-2votes
1answer
15views
What is the use of comma operator in python iteables?
Solution:
Can anyone tell what is the use of , operator at the end of the 6th and 7th line?
1vote
1answer
26views
how show multiple array in pandas dataframe with python
Array :
[{'base': 'BTC', 'target': 'USDT', 'market': {'name': 'Binance', 'identifier': 'binance', 'has_trading_incentive': False}, 'last': 40557.66, 'volume': 56710.07310532919, 'converted_last': {...
-1votes
2answers
35views
How to use zip in this case or any other solution? [closed]
I have an input like this:
Input = {1: [array([5, 2, 1, 10, 2, 1]), array([20, 2, 10, 1, 2, 1])], 2: [array([44, 1, 1, 4, 3, 3])}
I am looking for output like this:
Output = (5, 20, 44), (2, 2, 1), (...
0votes
1answer
19views
How to write to the file once instead of writing one number and tab at a time in python?
import numpy as np
a=np.array([1,2,3,4,5,6,7,8,9,10])
n=int(input("Enter the number of splits : "))
for i in range(n):
aa=...
-2votes
2answers
28views
Using numpy arrays for division
For the numpy function below why can I not get the expected output below. I get the same value of 25.00187514 as the output for all of the 3 variables inputted. I was expecting to get [25....