numpy

Reassign index of a dataframe

空扰寡人 提交于 2021-02-05 12:25:05
问题 I have the following dataframe: Month 1 -0.075844 2 -0.089111 3 0.042705 4 0.002147 5 -0.010528 6 0.109443 7 0.198334 8 0.209830 9 0.075139 10 -0.062405 11 -0.211774 12 -0.109167 1 -0.075844 2 -0.089111 3 0.042705 4 0.002147 5 -0.010528 6 0.109443 7 0.198334 8 0.209830 9 0.075139 10 -0.062405 11 -0.211774 12 -0.109167 Name: Passengers, dtype: float64 As you can see numbers are listed twice from 1-12 / 1-12, instead, I would like to change the index to 1-24. The problem is that when plotting

NumPy stack or append array to array

让人想犯罪 __ 提交于 2021-02-05 12:10:47
问题 I am starting with NumPy. Given two np.array s, queu and new_path : queu = [ [[0 0] [0 1]] ] new_path = [ [[0 0] [1 0] [2 0]] ] My goal is to get the following queu : queu = [ [[0 0] [0 1]] [[0 0] [1 0] [2 0]] ] I've tried: np.append(queu, new_path, 0) and np.vstack((queu, new_path)) But both are raising all the input array dimensions except for the concatenation axis must match exactly I didn't get the NumPy philosophy. What am I doing wrong? 回答1: In [741]: queu = np.array([[[0,0],[0,1]]])

NumPy stack or append array to array

梦想的初衷 提交于 2021-02-05 12:07:26
问题 I am starting with NumPy. Given two np.array s, queu and new_path : queu = [ [[0 0] [0 1]] ] new_path = [ [[0 0] [1 0] [2 0]] ] My goal is to get the following queu : queu = [ [[0 0] [0 1]] [[0 0] [1 0] [2 0]] ] I've tried: np.append(queu, new_path, 0) and np.vstack((queu, new_path)) But both are raising all the input array dimensions except for the concatenation axis must match exactly I didn't get the NumPy philosophy. What am I doing wrong? 回答1: In [741]: queu = np.array([[[0,0],[0,1]]])

TypeError: 'numpy.float64' object does not support item assignment - Similar code, error raises

半腔热情 提交于 2021-02-05 11:27:13
问题 I am writing a Molecular Dynamics code and for that I have a function that computes forces between particles: conservative, random and dissipative forces. The conservative forces are pairwise forces, which means I have a double loop for to compute them. I wanted to save some time and include the calculation of the random and dissipative forces in one of the loops of the double loop as follows: fr = np.zeros((npart, dim)) fd = np.zeros((npart, dim)) fc = np.zeros((npart, dim)) for i in range

plotting wrong on x axis

こ雲淡風輕ζ 提交于 2021-02-05 10:59:48
问题 thank you for reading my question I have to plot my data like that. When I plot my data I am having an output like this. Code for reading the data from the file and plotting is below #!/usr/bin/env python3.8 import matplotlib.pyplot as plt import numpy as np with open('data.txt','r') as file2: y= [line.rstrip('\n') for line in file2] notf2=y[2:] z=[a.rstrip(' ') for a in notf2] x_data=[] y_data=[] for j in range(0, len(z)): x_data += [z[j][:3]] y_data += [z[j][5:]] x__data=[] y__data=[] for k

InvalidArgumentError: Input to reshape is a tensor with 27000 values, but the requested shape has 810000 [Op:Reshape]

半城伤御伤魂 提交于 2021-02-05 10:42:07
问题 Getting the following error message when setting up a 3D-GAN for ModelNet10: InvalidArgumentError: Input to reshape is a tensor with 27000 values, but the requested shape has 810000 [Op:Reshape] In my opinion the batch is not properly created and thereby the shape of the tensor is not valid. Tried different things but can´t get the batch set up.. I am more than thankful for any hints how to clean up my code! Thanks in advance! import time import numpy as np import tensorflow as tf np.random

More efficient way to remove last N values fom np.array

余生长醉 提交于 2021-02-05 09:47:41
问题 I am working with np.arrays. I am trying to remove the last n elements, where n can be also 1. n=5 corr=np.full(10,10) Usually I use this approach with array slicing: corr=corr[:-n] But I was thinking of using np.delete to increase the performance: np.delete(corr,range(-n,0)) But it doesn't work, is there any better solution compare with array slicing? (method able to deal also with case in which n=0, would be a point of advantage) 回答1: An array is an object with attributes like shape , dtype

Memory error utilizing numpy arrays Python

好久不见. 提交于 2021-02-05 09:27:18
问题 My original list_ function has over 2 million lines of code and I get a memory error when I run the code that calculates . Is there a way I could could go around it. The list_ down below isa portion fo the actual numpy array. Pandas data: import pandas as pd import math import numpy as np bigdata = 'input.csv' data =pd.read_csv(Daily_url, low_memory=False) #reverses all the table data values data1 = data.iloc[::-1].reset_index(drop=True) list_= np.array(data1['Close'] Code: number = 5 list_=

Is there a way to fill one side of the gyroid surface by using Mayavi?

心不动则不痛 提交于 2021-02-05 09:22:31
问题 I'm using Mayavi to plot an iso-surface of a gyroid. My problem is that I need a more solid structure by filling one side of the two generated areas. In the following pictures, you can see how my generated iso-surface looks like and how it should look like after filling one side. My generated iso-surface: How it should look like: The iso-surface can be generated by the following equation: U = sin(2*pi * x/a) * cos(2*pi * y/a) + sin(2*pi * y/a) * cos(2*pi * z/a) \ + sin(2*pi * z/a) * cos(2*pi

Is there a way to fill one side of the gyroid surface by using Mayavi?

我的梦境 提交于 2021-02-05 09:22:26
问题 I'm using Mayavi to plot an iso-surface of a gyroid. My problem is that I need a more solid structure by filling one side of the two generated areas. In the following pictures, you can see how my generated iso-surface looks like and how it should look like after filling one side. My generated iso-surface: How it should look like: The iso-surface can be generated by the following equation: U = sin(2*pi * x/a) * cos(2*pi * y/a) + sin(2*pi * y/a) * cos(2*pi * z/a) \ + sin(2*pi * z/a) * cos(2*pi