Tagged Questions
1
vote
2answers
13 views
Numpy savez / load thousands of arrays, but not in one step
I would like to store approx 4000 numpy arrays (of 1.5 MB each) in a serialized uncompressed file (approx 6 GB of data). Here is an example with 2 small arrays :
import numpy
d1 = { 'array1' : ...
0
votes
0answers
7 views
How to annotate a point in a subplot, and highlight it in the adjacent subplot in matplotlib
I want to create a reduced scatter plot matrix which will be composed by three subplots (like the one in this link Is there a function to make scatterplot matrices in matplotlib?). I have extracted ...
1
vote
1answer
10 views
Read file elements into 3 different arrays
I have a file that is space delimited with values for x,y,x. I need to visualise the data so I guess I need so read the file into 3 separate arrays (X,Y,Z) and then plot them. How do I read the file ...
2
votes
2answers
34 views
putting value of one array into a list in python [duplicate]
I am very new to python and I have a line of code
print docClassifier.predict(temp)
which basically prints an array of this format [0,0,1,1,1,0....]. Now I want to store this array in a list for ...
2
votes
2answers
51 views
How to eliminate for-loop and use list comprehension when using numpy array?
I am trying to avoid using for-loop with numpy array.
If I have a code that looks like below:
psimaps = [np.zeros((10,10)) for i in range(len(features)-1)]
for k in range(len(features)-1):
if ...
2
votes
3answers
48 views
Check that all rows in numpy array are unique
I have a 4 column array:
A=array([[100,1,500,1],
[100,1,501,1],
[101,1,501,1],
[102,2,502,2],
[500,1,100,1],
[100,1,500,1],
[502,2,102,2],
...
0
votes
5answers
31 views
adding list indexes in python
Say I have this list:
[['1', '1', '1', '1', '1', '.12'], ['1', '1', '1', '1', '1', '.13']]
And I want to add together the final element of each array (.12 and .13), how do I convert these strings ...
2
votes
1answer
54 views
For loop on two arrays of points
I have two arrays of points: list1 with list1.shape = [N, 3] and list2 with list2.shape = [M, 3]. Within N, M: the total number of point, (x, y, z) are 3 coordinates in 3D.
Now I want to check if ...
5
votes
4answers
74 views
Construct single numpy array from smaller arrays of different sizes
I have an array of values, x. Given 'start' and 'stop' indices, I need to construct an array y using sub-arrays of x.
import numpy as np
x = np.arange(20)
start = np.array([2, 8, 15])
stop = ...
0
votes
2answers
20 views
Get bit on n position from all elements in ndarray in python
i have a 3D array of int32. I would like to transform each item from array to its corresponding bit value on "n" th position. My current approach is to loop through the whole array, but I think it can ...
0
votes
1answer
17 views
How does the axis parameter from NumPy work?
Can someone explain exactly what the axis parameter in NumPy does?
I am terribly confused.
I'm trying to use the function myArray.sum(axis=num)
At first I thought if the array is itself 3 ...
0
votes
1answer
18 views
Max value of array won't save ASCII text to file
I am reading points from a frequency spectrum graph into an array like this:
self.iq_fft = self.dofft(self.iq)#Gets values of all data point in block (in dB)
x = self.iq_fft #puts values into x for ...
2
votes
2answers
44 views
How to apply multiple functions to numpy array?
I know how to vectorize() or apply function along axis .. but my case is a bit different.
I have 1D array (z) that contains 1 or 0 and then I have a 2D array (x).
I want to apply two different ...
2
votes
1answer
34 views
Extracting specific values from .npy file
I have a .npy file of which I know basically everything (size, number of elements, type of elements, etc.) and I'd like to have a way to retrieve specific values without loading the array. The goal is ...
2
votes
2answers
55 views
Passing numpy string-format arrays to fortran using f2py
My aim is to print the 2nd string from a python numpy array in fortran, but I only ever get the first character printed, and it's not necessarily the right string either.
Can anyone tell me what the ...
0
votes
1answer
27 views
Pb converting a list of pandas.Series into a numpy array of pandas.Series
I would like to convert a list of pandas.Series into a numpy array of pandas.Series. But when I call the array constructor, it also converting my Series.
>>> l = ...
1
vote
0answers
40 views
Fast array/list type for holding numpy ndarrays
I have a lot of list of numpy ndarrays, of different sizes, in my code.
(I also have lists of lists of numpy ndarrays, but that is less issue as those lists are small (<5 elements).)
I have learn ...
0
votes
2answers
38 views
Multidimensional Array sets multiple rows/columns
So I am having a strange problem in python. I am using the code below to create a plot of places where the object has been. Here is my code:
def GoForward(self, duration):
if (self.TowardsX - ...
1
vote
2answers
54 views
Python funny array indexing
I came across this code in Python:
processed = data[:,feature_locs]
I tried testing this sort of code out with this
ha = (3, 5, 7)
print ha
data = [1, 2, 3, 4, 5]
print data[:, ha]
...
0
votes
7answers
44 views
Convert list of numbers into two arrays in Python
I'm trying to create a network, given the edge list. I have a list of the edges, but I need to have two arrays, "from" and "to", to create the edges.
This is the data I have:
0,32 0,33 0,34 1,3 ...
0
votes
1answer
52 views
Three Sum Style Algolrithm [on hold]
I apologize in advance for any misgivings in my typing. This is my first post to stackoverflow and I'm not fully aware of the ettiquite.
So I am being asked to create a program that is very similiar ...
0
votes
1answer
37 views
Python averaging with ndarrays, csvfile data
In a folder, I have a number of .csv files (count varies) each of which has 5 rows and 1200 columns of numerical data(float).
Now I want to average the data in these files (i.e. R1C1 of files gives ...
1
vote
1answer
40 views
how do you use the indices in a numpy array for calculations
So I want the perimeterpoints function to work, but I am not sure how to run through the indices of my array. I thought len of my array would work, but it said 'in' object is not iterable. So if I had ...
3
votes
3answers
35 views
Array reshaped according to keys
I don't know the exact technical terms for what I wish to do, so I'll try and demonstrate with an example:
I have two vectors the same length, a and b, as below:
In [41]:a
Out[41]:
array([ ...
2
votes
3answers
54 views
Numpy hstack - “ValueError: all the input arrays must have same number of dimensions” - but they do
I am trying to join two numpy arrays. In one I have a set of columns/features after running TF-IDF on a single column of text. In the other I have one column/feature which is an integer. So I read in ...
3
votes
1answer
56 views
Doing Calculations On a Two-Dimensional Array Using For Loop
I have a 9X51100 two-dimensional array (9 different datasets, 51,100 daily files) and I'm attempting to take 140 yearly averages of the data and append them to a new array. However, numpy.append needs ...
0
votes
4answers
42 views
Convert string in python to nd-array [duplicate]
Below is the data response from a call the the Yahoo! Finance API, the data is there, but it is a giant string. Any bright ideas of how to convert this to an array with Date, Open, High, Low, Close, ...
1
vote
1answer
40 views
Selecting an adjacent element from a numpy array
I'm representing an upright square lattice with a numpy array (one element is connected to the one above, one below, to the right and to the left, but not diagonally). I need to select a random ...
1
vote
3answers
49 views
Can array.array() be used to define a 2d array?
I am new to Python. I am using Python 2.7.
I want to creat a 2D array, I know how to do it using a list. But the data is large by using a list.
In order to save memory, I want to use array rather than ...
2
votes
1answer
35 views
precision in variables extracted from array using numpy
I am loading an array using numpy.genfromtxt. I extract a variable from the array and save it into another .txt file, however the output will have many trailing digits.
Here is an example of my ...
0
votes
2answers
31 views
Generating array of array of divisors in python
I wish to get divisors of number n as a list stored in a master list at nth position. For example the sieve of length 11, I want sieve[6] == [2,3,6] (ignoring 1). My code below does not work and ...
0
votes
2answers
38 views
converting a string of floats into float array in python
I am trying to read a csv file and make an array of arrays of the rows of data. Here is my code:
import csv
def main():
a = range(4)
x = 0
with open('test.csv', 'rb') as csvfile:
...
0
votes
0answers
19 views
numerical method using python2-LU decomposition with pivoting
i read a piece of code in the book 'numerical method in engineering with python'.but i do not get the idea,could somebody explain it to me?(the code is about the LU decomposition)
code:
from numpy ...
0
votes
1answer
28 views
csv row import into python array
I have csv file in the following format
a b c d
1 12.0 3.5 4.3 5.9
2 13.0 5.7 2.8 5.2
3 14.0 6.4 9.7 2.3
4 15.0 6.8 4.7 3.4
I ...
0
votes
0answers
30 views
Intelligent Binary Array Padding Algorithm: pd.Timestamp(parse($myDate)).value
How can I create an array that pads in 0s for 5-minute time ranges not occurring within the specified time range (in a format like 11:00A 12:30P) and 1s where a 5-minute time range falls within the ...
0
votes
1answer
46 views
How to compress a matrix into an array/set in NumPy the fastest?
How can I make a matrix like mat0 = np.array([[1,2,3],[4,5,6],[7,8,9]]) flatten to an array like arr0 = np.array([1,2,3,4,5,6,7,8,9])? Or perhaps a set?
0
votes
3answers
42 views
Create and add a new array
I have a while loop that pulls down values and prints them individually. How can I get these individually printed values into one array? Ideally I would put something in my while loop and ...
0
votes
2answers
38 views
Make Python Lists Into Two-Dimensional Arrays
I'm reading in data and want to make a two-dimensional array. I have nine separate datasets and after I read in all of them, I'd like a 9Xwhatever array. Right now, when I ask for the shape of tmax, ...
1
vote
2answers
39 views
Numpy array indexing and/or addition seems slow
I was playing around with benchmarking numpy arrays because I was getting slower than expected results when I tried to replace python arrays with numpy arrays in a script.
I know I'm missing ...
2
votes
1answer
27 views
Getting the first occurrence of a value in an N-dimensional numpy array
I have seen this question, but want to reduce the array created from mask = array == value
mask = array([[[ True, True, True],
[False, True, True]],
[[False, True, ...
0
votes
2answers
20 views
TypeError: 'int' object is not callable in list
I was trying out a program for legendre's function as given below, but it showed some error. I'm not used to arrays in Python, but know them in C++.
from math import *
j = 0
arr = [0 for i in ...
2
votes
2answers
51 views
Array slice maximum that depends on the index of the previous axis
So I have a large 2D array, coming from a tiff image, in which I want to calculate the center of mass. To do that, I am using the indices of the image (as coordinates) and the average function:
from ...
0
votes
1answer
46 views
Convert floating point array to integer array?
I have an array known as start. I am trying to use it as a key in a dictionary known as G.
Here is a sample of the array:
array([(1497315, 11965605), (1502535, 11967915), (1501785, 11968665),
...
0
votes
0answers
20 views
pyCharm Debugging: Variable Inspection, how to get more values?
I am dealing with rather large arrays and when I debug, I need to inspect them.
The problem is though that pyCharm only shows a minority of all values within the array.
For instance, if I debug my ...
0
votes
6answers
69 views
How does one test if a matrix in Python has only 1's and 0's?
Let's say I've got a matrix like this:
mat1 = np.array([1,0,1], [1,1,0], [0,0,0]);
And I've got another one like this:
mat2 = np.array([0,1,0], [0,0,1], [1,1,1]);
I want to detect if something ...
0
votes
1answer
36 views
Creating a list of ctypes [duplicate]
I want to create a list of ctypes.c_int32's
I have read and understand Unexpected feature in a Python list of lists.
No matter what I do, I keep creating a list of one instance of the c_int32. This ...
3
votes
1answer
87 views
Creating same random number sequence in Python, NumPy and R
Python, NumPy and R all use the same algorithm (Mersenne Twister) for generating random number sequences. Thus, theoretically speaking, setting the same seed should result in same random number ...
2
votes
1answer
15 views
How to use PyArray_SearchSorted in Numpy C API
In a C extension, I am accessing two arrays passed to the function:
PyObject *xw_array = PyArray_FROM_OTF(xw_obj, NPY_DOUBLE, NPY_IN_ARRAY);
PyObject *x1_array = PyArray_FROM_OTF(x1_obj, NPY_DOUBLE, ...
0
votes
3answers
35 views
How to set the items/numbers in my array to integers?
I would like to add items to my array, but these items should be integers. I would need to explain each line of code, so please detailed answers.
I have a suitcase and want to add items into it. So ...
0
votes
1answer
33 views
How to overstep maxsize in python?
It is said from http://docs.python.org/2/library/sys.html that maxsize is [...] the maximum size [...] ! And guess what ? I need to overstep it !
On my 64 bits system, it comes that maxsize = ...