Latest Questions tagged Numpy

Browse all latest questions tagged Numpy

12
Votes
Published 31 Aug, 2022
Python - What does 'numpy.ndarray' object has no attribute 'barh' mean and how to rectify it?

I want to plot a 5 x 4 plots. The code for the same is below fig, axis = plt.subplots(5, 4,figsize=[25,10]) i = 0 for channel in np.unique(data_recent['channel_id']): for year in np.unique(data_r...

21
Votes
Published 31 Aug, 2022
Python - Create pandas dataframe from numpy array

To create a pandas dataframe from numpy I can use : columns = ['1','2'] data = np.array([[1,2] , [1,5] , [2,3]]) df_1 = pd.DataFrame(data,columns=columns) df_1 If I instead use : columns = ['1',...

53
Votes
Published 27 Aug, 2022
Python - Convert numpy.array object to PIL image object

I have been trying to convert a numpy array to PIL image using Image.fromarray but it shows the following error. Traceback (most recent call last): File "C:\Users\Shri1008 Saurav Das\AppData...

31
Votes
Published 31 Aug, 2022
Python - Tensorflow hashtable lookup with arrays

I'm trying to get HashMap type of functionality to work with tensorflow. I got it to work when keys and values are of int type. But when they are arrays it gives error - ValueError: Shapes (2,) and ()...

13
Votes
Published 01 May, 2022
Python - How to duplicate each row of a matrix N times Numpy

I have a matrix with these dimensions (150,2) and I want to duplicate each row N times. I show what I mean with an example. Input: a = [[2, 3], [5, 6], [7, 9]] suppose N= 3, I want this output:...

97
Votes
Published 21 Aug, 2022
Python - Counterclockwise sorting of x, y data

I have a set of points in a text file: random_shape.dat. The initial order of points in the file is random. I would like to sort these points in a counter-clockwise order as follows (the red dots are...

80
Votes
Published 26 Aug, 2022
Python - Python - Alternative for using numpy array as key in dictionary

I'm pretty new to Python numpy. I was attempted to use numpy array as the key in dictionary in one of my functions and then been told by Python interpreter that numpy array is not hashable. I've just...

40
Votes
Published 29 Aug, 2022
Python - TypeError: Mismatch between array dtype ('float64') and format specifier

I have a numpy array with dimension 1000*30*150. I am trying to save it as txt file. So far I have tried this np.savetxt("test.txt", mydata, fmt='%.5f', delimiter=",") #and with open('test.txt', 'w'...

55
Votes
Published 31 Aug, 2022
Python - Numpy decimal points precision of complex numbers

Consider the following Python code which does some simple arithmetic operations over complex numbers in Python: import numpy as np s = 2 l = 5 v = np.array([np.exp(1j*2*np.pi/l)]) A = pow(s*v, l) +...

97
Votes
Published 22 Aug, 2022
Python - How to one-hot-encode sentences at the character level?

I would like to convert a sentence to an array of one-hot vector. These vector would be the one-hot representation of the alphabet. It would look like the following: "hello" # h=7, e=4 l=11 o=14 wo...

29
Votes
Published 25 Aug, 2022
Python - Save pandas dataframe with numpy arrays column

Let us consider the following pandas dataframe: df = pd.DataFrame([[1,np.array([6,7])],[4,np.array([8,9])]], columns = {'A','B'}) where the B column is composed by two numpy arrays. If we save t...

112
Votes
Published 25 Aug, 2022
Python - TensorFlow getting elements of every row for specific columns

If A is a TensorFlow variable like so A = tf.Variable([[1, 2], [3, 4]]) and index is another variable index = tf.Variable([0, 1]) I want to use this index to select columns in each row. In thi...

94
Votes
Published 29 Aug, 2022
Python - argsort for a multidimensional ndarray

I'm trying to get the indices to sort a multidimensional array by the last axis, e.g. >>> a = np.array([[3,1,2],[8,9,2]]) And I'd like indices i such that, >>> a[i] array([[1, 2,...

45
Votes
Published 29 Aug, 2022
Python - Quadratic Program (QP) Solver that only depends on NumPy/SciPy?

I would like students to solve a quadratic program in an assignment without them having to install extra software like cvxopt etc. Is there a python implementation available that only depends on NumPy...

2
Votes
Published 01 May, 2022
Python - How to convert pandas DataFrame into bytes and vice versa?

I am trying to send a dataframe using socket programming.For that I need to know how to encode a dataframe into bytes at the client and then decode it into a dataframe at the server.