Tagged Questions
0
votes
1answer
54 views
Indexing in Python
So, I have this bit of code here that I'm working on for a school
def sem1Sort(semester1, selectionSEM1):
for semester1["1"] in semester1:
if semester1["1"] in selectionSEM1:
...
0
votes
1answer
22 views
Shapes of the np.arrays, unexpected additional dimension
I'm dealing with arrays in python, and this generated a lot of doubts...
1) I produce a list of list reading 4 columns from N files and I store 4 elements for N times in a list. I then convert this ...
0
votes
4answers
65 views
Finding common elements in list in python
Finding common elements in list in python?
Imagine if i have a list like follows
[[a,b],[a,c],[b,c],[c,d],[e,f],[f,g]]
My output must be
[a,b,c,d]
[e,f,g]
How do i do it?
What i tried is like this
...
0
votes
0answers
12 views
Accessing Data from .mat (version 8.1) structure in Python
I have a Matlab (.mat, version >7.3) file that contains a structure (data) that itself contains many fields. Each field is a single column array. Each field represents an individual sensor and the ...
0
votes
1answer
20 views
creating a python pandas dataframe from a list of dictionaries when one entry of each dictionary is itself an array
I am trying to create a dataframe from a list of dictionaries. However, one entry of this list is itself an array (or could be a pandas.Series). I need to do grouping and averaging and I could not get ...
0
votes
1answer
28 views
convert string numpy array to a ascii numpy matrix
I have been looking for an efficient way for converting a string numpy array to a two dimensional ASCII matrix in python. So for this is the best that I could come up with
def ...
0
votes
3answers
23 views
assign names to elements of unknown size list in python
consider I have input list contains elements 19 14 36 how to assign a name to each element say A for 1st element, B for 2nd and C for 3rd and the output is sorted list ( 14, 19, 36) but the printed ...
2
votes
4answers
42 views
Returning multiple values from a Python function
How do I pass the return statement from calculateTuitionIncrease into an array and then use that array when calculating the total cost?
Here's my code:
import math
def ...
0
votes
1answer
35 views
Python 'astype' not working
I am currently using Spyder from Anaconda and I am trying to convert an array containing type float to type int:
x = np.array([1, 2, 2.5])
x.astype(int)
print x
The result still comes out ...
1
vote
2answers
26 views
numpy.resize() rearanging instead of resizing?
I'm trying to resize numpy array, but it seems that the resize works by first flattening the array, then getting first X*Y elem and putting them in the new shape. What I want to do instead is to cut ...
0
votes
1answer
17 views
VTK to Maplotlib using Numpy
I want to extract some data (e.g. scalars) from a VTK file along with their coordinates on the grid then process it in Matplotlib. The problem is I dont know how to grab the point/cell data from the ...
0
votes
0answers
23 views
numpy array creation using np.indices() [on hold]
Can somebody explain in detail how np.indices() array creation is used and some useful examples? I have read the numpy documentation but I cannot really understan the logic behind and why is this ...
0
votes
1answer
19 views
confused about this error in printing array in python?
Consider the following code; I want to print the array Ptimes 3 spaces from the beginning of console screen. I have tried
print " %s" %(Ptimes)
when I use this form nothing printed it says that ...
3
votes
2answers
35 views
What is the Python numpy equivalent of the IDL # operator?
I am looking for the Python numpy equivalent of the IDL # operator.
Here is what the # operator does:
Computes array elements by multiplying the columns of the first array
by the rows of the ...
0
votes
1answer
54 views
Python array, unnecessary space
I am trying to read a file and create an array from it. The file is as follows:
1 0
0 1
The code is:
line = file.read()
array = np.fromstring(line.strip(),dtype = bool, sep = " ")
...
1
vote
4answers
29 views
In pandas/python, reading array stored as string
I have a pandas dataframe where one of the columns has array of strings as each element.
So something like this.
col1 col2
0 120 ['abc', 'def']
1 130 ['ghi', 'klm']
Now when i store this to ...
2
votes
2answers
69 views
Python numpy or pandas equivalent of the R function sweep()
What is numpy or pandas equivalent of the R function sweep()?
To elaborate: in R lets say we have a coefficient vector (say beta - numeric type) and an array (say data - 20x5 numeric type). I want to ...
0
votes
1answer
9 views
Indicating format of multiple numbers in numpy.savetxt
I want to save an array using numpy.savetxt. The array contains eight numbers. Only the format of the first number is different with respect to the latter seven. I know I can set the format of numbers ...
-2
votes
0answers
12 views
asking about function deals with input arrays in python?
I have a self learning practice assignment to implement the CPU scheduler algorithms in a simple console application. Is there a function that sorts arrays based on other array inputs (First come ...
-4
votes
0answers
33 views
How can i implement function in python that takes numbers and sort it? [on hold]
I have an assignment to implement the CPU scheduler algorithms in a simple console application. Is there a function that sorts arrays based on other array inputs (First come first serve algorithm ...
2
votes
1answer
29 views
Extending numpy arrays
I'm new to Python/numpy.
I'm trying to extend numpy.array to give it some functions that make it nice for representing images (e.g. convert to greyscale etc).
import numpy as np
import cv2
from ...
1
vote
2answers
22 views
Numpy: Create a mask array to select rectangle
Is there a way to generate an array, masking a rectangular area, without the need to initialize an empty array first?
mask = np.zeros((10,10), dtype=bool)
mask[10/2:,10/2:] = True
Im looking for ...
2
votes
1answer
39 views
Python, write dictionary values in an excel file
I have a dictionary with multiple values for each key. I add the values using the following code
d.setdefault(key, []).append(values)
The key value correspondence looks like this:
a -el1,el2,el3
b ...
1
vote
2answers
20 views
Extract elements of an N-dimensionnal array within a list in Python
I have the following problem. I save a large amount of data within a class. Most of these data are time dependent and in the most complex cases, the variables are 3-dimensionnal array.
Because list ...
2
votes
2answers
39 views
Iteration to update 2 dimensional array
Hi so essentially I have the basic text file:
3
1 0 1
0 1 0
1 1 1
And I'm trying to create a 2 dimensional array that contains the values as integers.
My code so far is:
import numpy as np
f = ...
0
votes
3answers
51 views
How to multiply array of ones by random numbers
I am trying to multiply each value in my array of ones by a random number. Each time I try by a method of iteration, I get an error saying: 'IndexError: index out of bounds.'
Here is my code:
from ...
1
vote
4answers
58 views
Python removing all negative values in array
What is the most efficient way to remove negative elements in an array? I have tried numpy.delete and Remove all specific value from array and code of the form x[x != i].
For:
import numpy as np
x = ...
1
vote
2answers
19 views
Identifying range of x array indices to set corresponding y array values to zero
Say I have data in t and y arrays. I want to identify the array element indices between t=0.5 to t=1.5 and t=3 to t=4 in order to set the corresponding y values to zero (and put this in ynew array). I ...
0
votes
1answer
26 views
Reduce python loop to array calculation
I am trying to fill an array with calculated values from functions defined earlier in my code. I started with a code that has a similar structure to the following:
from numpy import cos, sin, arange, ...
-1
votes
1answer
32 views
Find negative and positive values in numpy array
I have a numpy array what contains data of m/s wind speed. Both negative and positive values. Now i need to calculate the average number of the wind speed over the negative values and do the same for ...
1
vote
1answer
20 views
How can be used multiple filter in the numpy array?
I am trying to filter some data out from an array
data = data[data['RotSpeed'] <= ROTOR_SPEED ]
data = data[data['HorWindV'] <= WIND_SPEED ]
I am wondering if this can be optimized by ...
0
votes
1answer
31 views
Assigning comma separated strings to an array of tuples - python, numpy
Some shell escape command gives me:
a=!ls /cygdrive/s | grep "^Something6" | tr -d [A-Za-z] | sed "s/_.*$//" | sed "s/-/ /" | sed "s/ /,/"
['64,2014-04-01',
'64,2014-04-02',
...
1
vote
3answers
45 views
Numpy - How to replace elements based on condition
I have a numpy array, say:
>>> a=np.array([[0,1,2],[4,3,6],[9,5,7],[8,9,8]])
>>> a
array([[0, 1, 2],
[4, 3, 6],
[9, 5, 7],
[8, 9, 8]])
I want to replace the second and ...
0
votes
0answers
37 views
Coding Best rank k approximation
This code tries to compute the best k-rank approximation. But I keep getting this error:
Traceback (most recent call last):
File "frau.py", line 50, in <module>
secondRank = ...
1
vote
2answers
28 views
Python setting range of monotonic values in array to zero
If I have an array of monotonically increasing values, how do I set the end values to zero? For example:
import numpy as np
a = np.array([1.2,2.2,3.1,4.4,8.3,9])
b = 4.5
for i in ...
0
votes
0answers
31 views
Python - selecting range of values in ndarray
I have imported a .wav file into Python with wavfile.read and am using the frequency data to do an intensity -vs- frequency plot (with Fast Fourier Transforms).
Now I'm trying to isolate and plot ...
1
vote
3answers
30 views
Reading .dat without delimiters into array in python
I have a .dat file with no delimiters that I am trying to read into an array. Say each new line represents one person, and variables in each line are defined in terms of a fixed number of characters, ...
1
vote
1answer
40 views
Is There a Way to Represent Distance Between Arrays on a 2d Graph?
I am writing a program for evolutionary research in python. The output of my program is a bunch of neural nets (graphs of fixed size/structure).
For all intents and purposes, the neural nets can be ...
0
votes
2answers
35 views
Replace String From Tuple Inside List
I currently have the following list:
data = [('b','..','o','b'),('t','s','..','t')]
I am trying to figure out a way to replace all instances of the '..' string to another string. In my instance, ...
0
votes
0answers
28 views
Differential archive of a large array series
I'm building a unit test framework for a specific program that operates on a large set of 2-dimensional arrays. These arrays contain floating-point numbers and are 500x700 in size. Each unit test ...
3
votes
3answers
47 views
Distance to non consecutive elements in a numpy array
Using numpy or itertools is there a efficient way to determine the distance to next non-consecutive elements.
> import numpy as np
> ...
1
vote
2answers
28 views
Split Numpy array using Index
I have 3D array as
pcar=[[xa ya za]
[xb yb zb]
.
.
[xn yn zn]]
and index array as
[0,1,0....,2]
which gives rows in pcar should go in which cluster so that I can plot it ...
0
votes
1answer
15 views
Tkinter widget creation using Python3 of Rasberry Pi. Create an array of checkbuttons
I wish to create an array of checkboxes and reference them as an array of some sort.
This makes writing the code a lot easier with shorter blocks.
The ideal situation would be something like this
for ...
2
votes
2answers
58 views
How can I get the mean value of an array?
I am trying to calculate the mean value of the last 10 elements.
First I am reading out the data from a file:
np.genfromtxt(filename,skip_header=6, names=True)
First I tried to use numpy.mean ...
1
vote
1answer
27 views
JSON to CSV in python convert issue
I am trying to convert a nested JSON object file into CSV.
Here is the sample of JSON
{
"total_hosts" : [
{
"TYPE" : "AGENT",
"COUNT" : 6
}
],
"installed" : [
...
2
votes
1answer
21 views
numpy.memmap map to save file
I'm trying to create random matrix and save it in binary file using numpy.save
Then I try to map this file using numpy.memmap, but it seems it maps it wrong.
How to fix it?
It seems it read .npy ...
2
votes
4answers
58 views
Python replace, using patterns in array
I need to replace some things in a string using an array, they can look like this:
array = [3, "$x" , "$y", "$hi_buddy"]
#the first number is number of things in array
string = "$xena is here $x and ...
2
votes
1answer
69 views
Python: How to find the a unique element pattern from 2 arrays?
I have two numpy arrays, A and B:
A = ([1, 2, 3, 2, 3, 1, 2, 1, 3])
B = ([2, 3, 1, 2])
where B is a unique pattern within A.
I need the output to be all the elements of A, which aren't present in ...
-1
votes
0answers
47 views
Not able to convert string to int in python
I'm using a file that has one number per line. My loop reads two lines at a time, using the first to point at indices in my two arrays. I'm trying to use the playerLine variable as my index to update ...
0
votes
2answers
25 views
Convert list into array dtype=int64 in Python
Can i convert this list:
[0, 1, 2, 3, 4, 5, array([6, 9], dtype=int64), 7, 8, array([6, 9], dtype=int64)]
into this:
[array([0], dtype=int64), array([1], dtype=int64), array([2], dtype=int64), ...