We’re rewarding the question askers & reputations are being recalculated! Read more.

All Questions

Tagged with
Filter by
Sorted by
Tagged with
0
votes
2answers
24 views

sorting a tuple that contains string and numbers in python

I have a list like this; List = [('apple 5', 12), ('apple 3', 2), ('apple 6', 10),('apple 4', 15), ('apple 9', 11), ('apple 7', 14), ('apple 18', 10), ('apple 16', 10),('orange 5', 4), ('orange 4', 7)...
0
votes
2answers
30 views

keep track of increment and decrement of values in python tuple

I have a list like below, list_ = [('a', 5), ('a', 6), ('a', 8), ('a', 2), ('a', 5), ('a', 9), ('a', 10), ('b', 3), ('b', 7), ('b', 6), ('b', 2), ('b', 6), ('b', 5), ('b', 10)] I ...
-2
votes
1answer
59 views

Can I store strings in python array?

from array import * val=array('u',["thili","gfgfdg"]) print(val) When I compiled above python code, the compiler showed an error. What is the problem in my code.can not store strings in python ...
1
vote
0answers
12 views

Pycharm typehint for Numpy array of objects

I have multiple numpy arrays with different objects. How can I give 'type-hint' to the Pycharm so that I can get methods of that class while coding? For example, import numpy as np class Test: ...
0
votes
1answer
8 views

try to print out a matrix NameError: name 'Qb_matrix' is not defined

I tried to print out a matrix using code as follow, however, it showed up nameerror. i wonder where specifically should i define the matrix? can python recognise the abbreviation as Qb to Q_bar? ...
0
votes
1answer
40 views

Python sorting arrays by element contained?

I'm looking to take a list of lists and sort them by an element contained in the contained lists. For clarification, I want to have a list like this code myList = [] myList.append([1, 2, 3]) myList....
0
votes
1answer
39 views

Is there a subtle difference between some_list[:] = another_list vs some_list = another_list?

Like the title asks, Is there a subtle difference between some_list[:] = another_list vs some_list = another_list I seen people do both and just ignored it, thinking of them as equivalents, but ...
-4
votes
0answers
34 views

Been asked to create a particle class in python

Hi ive been tasked to create a class for a particle. The very bottom block of code is test code which has been provided to test functionality of the class but mine does not pass the test and i dont ...
0
votes
2answers
42 views

Extract specific portions of a string variable into a list of arrays

I have a string variable in python which has the following contents: InputString = HEADER 6 BGNLIB 19, 4, 9, 16, 11, 15, 19, 4, 12, 16, 8, 30 LIBNAME case1_lib UNITS 0.0009999999999999998, 9....
1
vote
5answers
70 views

Shuffling an array in python

What I would like to do is shuffle an array in python. For example if I have this array: arr=[[1,1,1],[0,0,0],[0,0,0] I would like the 1's to be distributed in randomly in second, third and first ...
0
votes
0answers
17 views

perfomance problem using python to process big data

enter code here def cov(X): y=0 t=np.mean(X,axis=0,dtype=float) Matrix = [[0 for x in range(len(X[0]))] for y in range(len(X[0]))] Matrix=np.array(Matrix,dtype=float) length=len(X[0]) lengthRows=len(X)...
0
votes
2answers
28 views

How to put an array of strings with two variables into a text file?

I'm trying to make a text classifier app. I have an array of strings which contains two parameters separated by comma like below: pos_tweets = [('I love this car', 'positive'), ('This ...
1
vote
1answer
42 views

is there a faster way to create a array of elements of an empty array without using for loops

I want to create an array of elements. I can do it using a loop, but i want to know if there is another way, like an numpy function or something to do this in less timme. this is what i want to do: ...
-2
votes
0answers
26 views

Method called countA taking string as argument and returning numer of letters “A” [closed]

Write a program that has the following methods: A method called countA that takes a string as an argument. The method should return number of ‘a’ letters(Uppercase or lowercase) in this string. *...
0
votes
0answers
13 views

if(temp_similarity[k]==similarity[l]): ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

I am trying to compare the 2 values from the indexes of two different numpy arrays as below: if(temp_similarity[k]==similarity[l]): sum = sum+probabilities_train[l] break but i found the ...
-5
votes
3answers
63 views

Array A has elements. need to check if all are different or not. Python [duplicate]

I'm trying to write this program but I keep facing an issue I need to see if: array import numpy as np A = [1,2,3,4,5,6,20,40,2,4,5] if: print = "all elements are different" else: return; "...
0
votes
0answers
8 views

How to replicate python bytearray() in C++

I am trying to replicate the following code from python to C++. Any tips will be helpful. Info: I am sending this information to a serial device. arr=[100,100,3,1,1,1] for x in arr: ...
0
votes
2answers
40 views

How to compared two lists in python and return them in dictionary

I have two lists: names: ['Mary', 'Jack', 'Rose', 'Mary', 'Carl', 'Fred', 'Meg', 'Phil', 'Carl', 'Jack', 'Fred', 'Mary', 'Phil', 'Jack', 'Mary', 'Fred', 'Meg'] grades: [80, 88, 53, 80, 64, 61, 75, 80,...
-9
votes
0answers
38 views

best python projects (for students) [closed]

list of project ideas for python
-3
votes
0answers
36 views

python 3.7 - 3 x 3 array [closed]

The ojective of this Python program is to print a star(*) pattern using a 3×3 array (printing the user's input word by their position) and ask for input from the user. example: abc [0 0 0] [0 0 0] [0 ...
0
votes
1answer
36 views

How to select one element from each sub-array of a 2D array in python?

So you are given only a single variable in python: array = [ [1,2,3], [4,5,6], [7,8,9], [10,11] ] You want to be able to return a list of arrays containing only 1 element from each element of this ...
0
votes
1answer
23 views

How can I match & modify an array of dictionaries?

I'm currently stuck trying to match & modify two dictionaries against each other. At a high level, I have an array of dictionaries of potential answer_ids to each question: [{'2194241222': 'Not ...
0
votes
2answers
42 views

How to split a list of arrays in decreasing order using split function in python?

I am trying to take array input from user and split arrays in sub-arrays with 3 elements on each. If no. of elements in array is not evenly divisible by 3, I want to increase the size of smaller ...
0
votes
1answer
27 views

Time complexity of leetcode 287

If you go to leetcode.com/problems/find-the-duplicate-number/solution/ (problem 287) there is the following solution given: def findDuplicate(self, nums): seen = set() for num in nums: ...
1
vote
1answer
46 views

How to effectively generate an array of tuples using numpy [duplicate]

I would like to effectively generate a numpy array of tuples which size is the multiple of the dimensions of each axis using numpy.arange() and exclusively using numpy functions. For example: the size ...
0
votes
1answer
13 views

Creating a complex 2D-array from two 2D-real-arrays ? - Python 3

Consider the following two real 2D-array real = [x_00,x_01,....,x_0m] [x_10,x_11,....,x_1m] ...... [x_n0,x_n1,....,x_nm] imag = [y_00,y_01,....,y_0m] [y_10,y_11,....,y_1m]...
-1
votes
0answers
41 views

Unable to allocate array with shape

I am using pandas to do analysis on a text file which is having 28 columns and 2817826 rows separated by pipe(|) I want to do data analysis on this using pandas in python. Getting memory error while ...
0
votes
1answer
56 views

Numpy: How to find the arguments of 2D array inside another 2D array [duplicate]

Before posting this question, I have searched to find a solution on this website but cannot find any solution. Suppose that I have 2 numpy 2D arrays, a and b, such that: a = np.array([[0. , 1.], ...
0
votes
2answers
37 views

How to select elements from a python dictionary and put it in array using

How can I select specific elements, arrays or objects from python dictionary? and turn it Into array of python dictionaries (separated by the 'drug') From this {'entities': [{'confidence': 0....
0
votes
1answer
30 views

How to access different elements within an array with 2 parts per item

Using this example, cards = ['Ace of Spades':1, '2 of Spades':2, '3 of Spades':3, '4 of Spades':4, '5 of Spades':5, '6 of Spades':6, '7 of Spades':7, '8 of Spades':8, '9 of Spades':9, ...
0
votes
1answer
14 views

How do i store values from a text file into a 2D Numpy array?

I have a dataset on a txt file with 373 rows and 3 columns.My teacher asked me to create 2 arrays.The 'array1' stores all the rows of the dataset that their third column has the value 1,and the '...
0
votes
1answer
24 views

I want to recognize an image with TensorFlow. I'm getting a shape error, but what do I do?

GmdMiss_Folder = os.path.join(os.getcwd(), '..', 'Photo', 'GMD Miss') GmdMiss_List = os.listdir(GmdMiss_Folder) for i in range(0, len(GmdMiss_List)): Img = os.path.join(os.getcwd(), ...
-1
votes
0answers
40 views

convert my gray scale image in to blinking LED

I need to load a grayscale image and convert it into byte array.I need binary values of each pixel of whole image.then blink my led which has connected to arduino, for its all binary values. e.g.: 1 ...
-1
votes
5answers
47 views

How to change all columns value of a matrix in Python?

As the title says, I want to change all columns value to the same array using no external library besides numpy and without using for, while or something like that because what I'm looking for is ...
0
votes
1answer
25 views

python int to bytearray does not convert properly

I am trying to convert int to bytearray as follows: test = bytearray(struct.pack(">I", 60000)[2:]) print(test) The output is: bytearray(b'\xea`') Instead of: bytearray(b'\xea\x60') What seems ...
0
votes
0answers
6 views

Nested for-loops for 2D arrays in Python? [duplicate]

I'm trying to create a simple 2D array where every elements value is the sum of its index position in the array. For example the element at position (0,0) in the array will have the value 0, and the ...
0
votes
0answers
15 views

I want to dynamic arrays on the basis of the required. is it possible in python and yes then how?

Well, I want to create dynamic arrays with the help of the points which stores data in different arrays. I have thousands of data and they stores in various arrays so can anybody help me in this task? ...
0
votes
0answers
28 views

How can I print this 2D array in Python

I created a 2D array and want to print it in this format: Input: history = [['T:18:00,', 'Main,', 'exit'], ['T:10:00,', 'Main,', 'enter']] Output: Main (T:18:00 - T:10:00)
0
votes
0answers
10 views

Convert just a key in a dictionary to a numpy array

I have a dictionary that consists of three keys. one of the keys(Data) has 231 lists with values in an array. One list has values like the one below i.e. [0, -10, 0, -78, -5.27, 16.9]. I want to ...
-1
votes
2answers
36 views

I am trying to read an image into a folder and store it in an array, but I get an index error

Can't I save the pixel data of an image to a list? GmdMiss_Folder = os.path.join(os.getcwd(), '..', 'Photo', 'GMD Miss') GmdMiss_List = os.listdir(GmdMiss_Folder) for i in range(0, len(GmdMiss_List))...
0
votes
1answer
28 views

im working on arrays in python, a term called type array class confused me

So in my lab manual there is a task to make a function that takes 2 arrays as parameters both of type array class and returns the sum of them. Now im really confused with the words "type array class" ...
-2
votes
2answers
27 views

1 dimensional list to 2 dimensional list?

How can I convert this list = [a, b, c, d, e, f, g, h, i] to this list = [[a, b, c], [d, e, f], [g, h, i]] I want to separate the objects to groups of three in each.
-1
votes
0answers
24 views

How to calculate matrix with decomposition method

where the input values are: import numpy as np n = 16 delta = 0.1 W = -(1/delta)**2 t = 0 k1 = 10 k2 = -k1 sigma = 20*delta x0 = 10*delta x = np.linspace(k2,k1,n) PSI_0 = ((1/(np.pi*sigma**2)**0.25)*...
0
votes
0answers
30 views

Remove brackets for multidimensional array [duplicate]

I'm trying to remove the parenthesis and comma in a multidimensional array. I can remove the parenthesis at the first level in Python3 with print((*array3), sep = ', ') and in Python2.7 with print(' '....
0
votes
0answers
52 views

Modulo in Python

In the stock market of a city, the stock prices of a given day is calculated as 3 times the price of previous day plus 4 times the price of the day before yesterday. Given the prices on day 1 and day ...
0
votes
2answers
19 views

Can't figure out why two arrays are copy of each other

So I'm learning python and trying to code Conway's game of life : (link) I created a grid, on which you can click to select tiles, and a 2D array that contain the value 1 if the tiles is active, 0 if ...
-1
votes
0answers
28 views

Storing multi-dimensional arrays in a loop

In a for loop, for each iteration, I get a result of two multi-dimensional arrays result 1 = [[][][][]] result 2 = [[][][][]] The size of both arrays is 200x4. When I set the loop size to be 10 (0-...
0
votes
1answer
16 views

I am trying to read an image with python's cv2 and save it as an array, but I get a type error

I am trying to read an image with python's cv2 and save it as an array, but I get a type error. I tried switching to a numpy array, but got the same error. GmdMiss_Folder = os.path.join(os.getcwd(), ...
0
votes
2answers
28 views

How to take sum of only the second column of a matrix / multidimensional array using numpy

My array has two columns, the first being the letters of the alphabet (as single letter strings), and the second a number. I want to find the sum of these numbers but I get errors due to the strings. ...
0
votes
2answers
53 views

Why can't I print a random integer numpy array with range()

I'm trying to print a 2-D random integer numpy array but I'm getting an error. import numpy as np a=np.random.randint(100,size=(2,4)) for i in range(a): print(i) The error message says: "...