numpy-ndarray

3D array using data from existing lists

点点圈 提交于 2021-02-08 11:38:42
问题 I am new to python and am having trouble with multi-dimensional arrays. I have a list(s) of points in 3-dimensions(x,y,z) that I am trying to use in marching_cubes_lewiner(). The co-ordinate values are in 3 lists: x,y and z such that any point will be given by (x[i],y[i],z[i]). Now, marching_cubes_lewiner() accepts volume as a 3D numpy array. What would be the best way to convert the 3 lists into a 3D numpy array? I have tried: s=len(x) points = np.ndarray((s,s,s),buffer=np.array([x,y,z]),

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]]])

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_=

Numpy.where uses

放肆的年华 提交于 2021-01-29 19:32:18
问题 Use numpy.where to get all (R, G,B) in a numpy.array with a definite value of R, G and B The problem is i'm not sure i can use numpy.where to get what i want : i tried the following code : L = numpy.array([[1,2,3],[1,1,1],[1,1,1]]) print(numpy.where(L==(1,1,1))) (array([0, 1, 1, 1, 2, 2, 2], dtype=int64), array([0, 0, 1, 2, 0, 1, 2], dtype=int64)) and i understand it's returning me the coordinates of every element == 1 but i would like it to return the index in L of the element equal to (1,1

How do I plot an updating numpy ndarray in real time using matplotlib?

☆樱花仙子☆ 提交于 2021-01-29 17:29:41
问题 I have a numpy array which I initialized outside the loop using np.zeros. This array is updated using some function inside a for a loop. I wish to plot the array as it changes with each iteration. Most of the answers I have seen here are for lists and not ndarrays. I have seen the following links. Some of them I have tried to modify for my purpose but to no avail. How to update a plot in matplotlib? https://github.com/stsievert/python-drawnow/blob/master/drawnow/drawnow.py @Scott Sievert, I

PyTables create_array fails to save numpy array

假如想象 提交于 2021-01-29 17:27:03
问题 Why does the snipped below give: "TypeError: Array objects cannot currently deal with void, unicode or object arrays" ? Python 3.8.2, tables 3.6.1, numpy 1.19.1 import numpy as np import tables as tb TYPE = np.dtype([ ('d', 'f4') ]) with tb.open_file(r'c:\temp\file.h5', mode="a") as h5file: h5file.create_group(h5file.root, 'grp') arr = np.array([(1.1)], dtype=TYPE) h5file.create_array('/grp', str('arr'), arr) 回答1: File.create_array() is for homogeneous dtypes (all ints, or all floats, etc).

Optimizing Calculations with numpy and numba Python

不打扰是莪最后的温柔 提交于 2021-01-29 15:08:13
问题 I am trying to make python run standard deviation functions faster with numba and numpy. However the problem is the for loop is very slow and I need alternatives so that I could make the code much faster. I iterated numba to the already existing numpy version however there is not much of a gain in performance. My original list_ has million of values within it thus it is taking a very long time to compute the standard deviation function. The list_ function down below is a very short numpy

How to faster iterate over a Python numpy.ndarray with 2 dimensions

荒凉一梦 提交于 2021-01-29 13:06:10
问题 So, i simply want to make this faster: for x in range(matrix.shape[0]): for y in range(matrix.shape[1]): if matrix[x][y] == 2 or matrix[x][y] == 3 or matrix[x][y] == 4 or matrix[x][y] == 5 or matrix[x][y] == 6: if x not in heights: heights.append(x) Simply iterate over a 2x2 matrix (usually round 18x18 or 22x22) and check it's x. But its kinda slow, i wonder which is the fastest way to do this. Thank you very much! 回答1: For a numpy based approach, you can do: np.flatnonzero(((a>=2) & (a<=6))

How to add 2 columns in numpy ndarray? [duplicate]

随声附和 提交于 2021-01-29 11:43:02
问题 This question already has an answer here : How to combine two columsn/rows of a matrix in numpy by summing values? (1 answer) Closed 10 months ago . I have an numpy ndarray like below: [[1 9 1 1] [9 3 1 1] [1 9 9 1] [8 2 4 7]] I want to add last 2 columns values to get below result [[1 9 2] [9 3 2] [1 9 10] [8 2 11]] 回答1: Sum, then drop the last column myArray[:, -2] = myArray[:,-2] + myArray[:,-1] myArray = myArray[:,:-1] 来源: https://stackoverflow.com/questions/61092371/how-to-add-2-columns