Tagged Questions
0
votes
1answer
20 views
Create 2D array from where clause on 1D array numpy
I have a 1D array containing integer values:
a = np.array([1,2,3,3,2,2,3,2,3])
a
array([1, 2, 3, 3, 2, 2, 3, 2, 3])
I would like to create a 2D array with the first dimension holding the index of ...
1
vote
2answers
25 views
Memory Error with numpy on several large arrays
So I am trying to carry out the following calculations on a series of large arrays but I keep getting the error:
MemoryError
In total there are 9 grain_size arrays 2745 by 2654 (Note: I could use ...
2
votes
1answer
19 views
Obtain one number from numpy subarrays of size 2 given its peer
I have a array with pairs of numbers (subarrays of size 2) like this:
pairs = np.array([[1, 2],[5, 12],[9, 33],[9, 1],[34,7]])
and the peers array, like this:
nums = np.array([1,12,9])
What I ...
1
vote
3answers
25 views
numpy array print index of certain value
Given a numpy array
A = np.array([[[29, 64, 83],
[17, 92, 38],
[67, 34, 20]],
[[73, 28, 45],
[19, 84, 61],
[22, 63, 49]],
...
0
votes
1answer
38 views
Is there a faster way to search a numpy array
I have a numpy array of roughly 3125000 entries the data is structured using the following dtype
dt = np.dtype([('startPoint', '<u8' ), ('endPoint', '<u8')])
The data is from a file that has ...
0
votes
2answers
38 views
Determine sum of numpy array while excluding certain values
I would like to determine the sum of a two dimensional numpy array. However, elements with a certain value I want to exclude from this summation. What is the most efficient way to do this?
For ...
-1
votes
3answers
35 views
Numpy array construction using tuples
C = numpy.array([a^b for a,b in A,B])
Is what I attempted. I thought it would xor each individual element in A and B which are matrices of their own and store it as the same shape within C. How ...
1
vote
1answer
25 views
Python: Access index of moving window array that matches current position of array being looped over
I've coded up a neighbourhood smoothing filter that works on a user supplied 2D array - it works as it is but it could be far faster/less wasteful of memory as currently I am copying the entire input ...
2
votes
2answers
47 views
Producing an array from an ellipse
I have an equation that creates an ellipse in the general form x^2/a^2 + y^2/b^2 = 1. I wish to produce an array whereby all points inside the ellipse are set to one and all points outside are a zero. ...
0
votes
1answer
32 views
numpy.ndarray.shape changing dimension
The tuple holding the dimensions of a numpy array (numpy.ndarray.shape) changes size. E.g:
len(numpy.array([1,2,3]).shape) -> 1, shape=(1,)
len(numpy.array([[1,2,3],[4,5,6]]).shape) -> 2, ...
-4
votes
0answers
43 views
what is the difference between s=[[1,1], [1,1]] and s= [(1,1), (1,1)] in python [duplicate]
What is the difference between s=[[1,1], [1,1]] and s= [(1,1), (1,1)] in python
if you execute print s, I can't find out the difference.
1
vote
3answers
63 views
How to declare and fill an array in python?
I am new to python syntax not new to programing. I need to create an empty array in python and fill it in a loop method.
data1 = np.array([ra,dec,[]])
Here is what I have. The ra and dec portions ...
-1
votes
0answers
16 views
Multi-dimensional Python Array with Splunk
Working with Splunk, a python script grabs results of a search and presents them to the JavaScript. Here is my current code
dataset = getattr(job, entity_name)[offset: offset+count]
outputJSON = {}
...
2
votes
3answers
37 views
Comparing a numpy array object to multiple conditions
I am trying to use numpy.where to find the indices I want. Here's the code:
import numpy as np
a = np.array([20,58,32,0,107,57]).reshape(2,3)
item_index = np.where((a == 58) | (a == 107) | (a == 20))
...
0
votes
4answers
32 views
Simpler way to create a matrix/list of indices?
I wonder what could be the easiest way to create a bi-dimensional array, that has for each row the indices to another multi-dimensional array.
For example, let's say I have a cube 4x4, the "indices ...
1
vote
1answer
37 views
Binning data based on one column in 2D array and estimate mean in each bin using cython
In order to optimize the speed of my code which is very vital for the speed of my MCMC, I want to substitute some of the bottlenecks of my python code with cython. Since I am working with a huge two ...
0
votes
2answers
44 views
Determine range of elements that do not occur in any of several arrays
I have several arrays denoting x- and y-coordinates. What I would like to do is to determine the y-range for which none of the resulting lines overlap with one another. To illustrate what I mean I ...
2
votes
1answer
64 views
Indexing and slicing structured ndarrays
Now I'm trying to understand possible ways to index numpy structured arrays, and I kinda get stuck with it. Just a couple of simple examples:
import numpy as np
arr = np.array(zip(range(5), range(5, ...
0
votes
1answer
47 views
How to access data from Multidimensional Array
I have an array in python which looks like:
Edit: Sorry, the data looks like follows:
1. [array([[[23, 2]]]), array([[[21, 2]],
[[21, 3]],
[[21, 4]],
...
0
votes
1answer
16 views
Numpy return recarray with 'column headings' and 'dtype'?
I am following this example explicitly:
http://wiki.scipy.org/Cookbook/InputOutput#head-d528c8c74e765542c351a768b47c7bc9a2ca8e85
import numpy
def readarray(filename, dtype, separator=','):
...
0
votes
4answers
33 views
Associative array in python with keys as a fragment of array
How to better implement such thing:
Loop over the numbers. Each number in diapason and belong to one part of associative array.
E.g.
di = {}
di[ xrange(0,10) ] = "A"
di[ xrange(11,20) ] = "B"
...
1
vote
2answers
33 views
Python - turning text column into array, where I can access each number in the array
I have a text file containing multiple columns. I can successfully print all the items in the 2 columns I am interested in by using this code:
with open(file) as catalog:
for line in catalog:
...
0
votes
1answer
31 views
Manipulating a large binary image array with numpy and cv2
My code is the following:
import cv2; import numpy as np
class MyClass:
def __init__(self,imagefile):
self.image = cv2.imread(imagefile)
#image details
self.h,self.w = ...
0
votes
1answer
36 views
Numpy arctan2 of multidimensional array
I am trying to shape up some code that was written to take single float values, so it works fine using 1D (and eventually 2D) numpy.arrays as input.
Striped down to a minimal example the function ...
-5
votes
2answers
49 views
How do I add the values in a list together? Python
I'm currently learning Python and for my task it says to add the values of an array together. I tried:
no = ['1','2','3']
sum(no)
but had no luck in figuring out any way to find an answer. I'm also ...
-1
votes
2answers
37 views
Python Novice: Access an array in a separate file? [on hold]
I'm working on learning Python. I'm building a hangman app, and I have the user select the amount of letters in a word.
I'd have an array called Three, Four, Five, etc with the corresponding length ...
0
votes
1answer
34 views
Tracking indices with arrays?
For tracking indices this achieves a syntax closer to python's dictionaries.
byte item0 = 0;
byte item1 = 1;
byte item2 = 2;
byte[] anArray;
anArray = new byte[3];
anArray[item1] = 5;
...
-1
votes
1answer
29 views
Equivalent of LabVIEW Threshold 1D Array Function in Python
is there an equivalent of labview Threshold 1D Array Function:
http://zone.ni.com/reference/en-XX/help/371361H-01/glang/threshold_1d_array/
in python?
-1
votes
1answer
23 views
List stock data by weeks and days using Python
I would like to list different stock data which were published in one week. The stock data should all be in seperate arrays. The different array elements should represent the different days and the ...
-7
votes
2answers
45 views
Using Integer as Array Name in Python [on hold]
I would like to convert an integer to an array name in python. I have no idea whether this is even possible. Help is highly appreciated.
a = int(10)
print a["1"]
Should return >> 10["1"]
-2
votes
2answers
46 views
Re-arrangement within a numpy array
I have a numpy array that looks like as follows:
[ 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.
1. 1. 1. 1. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2.
2. ...
3
votes
1answer
55 views
Creating new numpy array from existing array efficiently
I have existing numpy array (uint8) which looks like this:
(Values are 8bit, i am interested only in last 3 of them)
[
[ 00000AAA, 00000BBB, 00000CCC ],
[ 00000FFF, 00000EEE, 00000DDD ],
...
2
votes
2answers
28 views
Ignoring negative values when using np.log(array)
When taking the log of a specific column within a numpy array, i.e., logSFROIIdC = np.log(data_dC[:, 9]) the compiler returns the error:
-c:13: RuntimeWarning: divide by zero encountered in log.
...
0
votes
1answer
16 views
Scikit-learn ValueError when implementing logistic regression in Python
I am new to machine learning and am trying to set up a logistic regression for prediction purposes in Python using scikit-learn. I already set one up with a small, mock dataset, but when expanding ...
1
vote
3answers
61 views
using index values to select items from a numpy array
Suppose I have a pair of numpy arrays X and I that look like this (X is 2D, I is 1D)
X I
-----------------
3.4 9.13 0
3.5 3.43 1
3.6 2.01 2
3.7 6.11 0
3.8 ...
1
vote
1answer
29 views
Access individual elements of an array of several arrays, Python
I am using a function that returns array of several arrays let say A. I don't know how to access each individual element. Thus, I am thinking to rearrange A to a matrix of two arrays so I could access ...
1
vote
1answer
31 views
How to get cumulated values from timestamped arrays in even intervals [PYTHON]
I have a numpy array with timestamps in seconds
For example, this array named a:
a = np.array(10,95,99,100,250)
Then I have an array b which gives me the amount of shares that come in ...
1
vote
3answers
27 views
Creating an array for each column of a data frame by column name
I am trying to create a number of arrays that correspond to the data values of each column in a large data frame, and I want each array to share the same name as its corresponding column. Here is an ...
0
votes
1answer
30 views
Reading in a text file as a numpy array with float values
I do not know python at all thus I have been unsuccessful in interpreting similar previous answers and using them.
I have a python script that I wish to execute in unix. The script uses an input file ...
0
votes
2answers
43 views
Python - What is wrong with my primes code?
I am currently writing a small piece of python code that prints out all the prime numbers until 1000. Here is my code:
primes = []
for prime in xrange(1, 1000):
for b in xrange(2, prime):
...
2
votes
1answer
41 views
Implementing np.subtract.outer for index of array([[array … structure in python
I have the following set of indices;
ind = array([[array([0, 1, 4])],
[array([0, 1, 2, 5])],
[array([1, 2, 3, 6])],
[array([2, 3, 7])],
[array([0, 4, 5, ...
1
vote
1answer
37 views
BytesIO stream to Numpy arrays? (Picamera)
I'm using Picamera with the Raspberry Pi to take pictures and then analyze the differences between them. I'm using the following code to capture to a BytesIO stream and then read that into a Numpy ...
2
votes
1answer
24 views
numpy irregularly strided array
Quoting the documentation on numpy array structure in memory:
Several algorithms in NumPy work on arbitrarily strided arrays.
However, some algorithms require single-segment arrays. When an
...
0
votes
2answers
100 views
Is there a best-practice for looping “all the way through” an array in C++?
In Python, one can compare each element of an array with the "next" element (including the last element with the first element) with the following code:
a = [0, 1, 2, 3]
for i in range(-1, 3):
if ...
2
votes
1answer
47 views
Apply a pairwise shapely function on two numpy arrays of shapely objects
I have two arrays of different length. One contains shapely polygons, the other contains shapely points. I want to run the a_polygon.contains(a_point) shapely function for every possible combination ...
0
votes
3answers
35 views
Augmenting a matrix in Python using numpy
I'm trying to augment a matrix to solve an equation, yet have been unable to. And yes, I saw the "Augment a matrix in NumPy" question; it is not what I need.
So my problem: create an augmented matrix ...
0
votes
3answers
23 views
Changing shape of numpy array read from a text file
I am working in python and am loading a text file that looks like this:
3 4
5 6
7 8
9 10
I use np.loadtxt('filename.txt') and it outputs an array like this:
([[3, 4]
[5, 6]
[7, ...
0
votes
1answer
51 views
Total size of array must be unchanged
I am using a Python module called emcee to sample a distribution. I need to pass a (37,100) (which I have named Ntrig and Nsamp, respectively) array called events to the below function.
def mp(SNR2, ...
0
votes
1answer
35 views
Assigning in Python, Arrays
I am creating an array of random values so that I can do different sorts and see how all of them interact. The problem is that when I call a sort on an array, I cannot then use that array again ...
0
votes
1answer
24 views
How to create bins
Currently I have bins created using the following code:
bin_volumes = [((i+1)**3 - i**3) * bin_width**3 *4 * np.pi/3 for i in range(num_bins)]
format of bins :
[(0.0, 0.10000000000000001), ...