473,399 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

How to replace only 1d values in 2d array after filter using numpy in python

How to replace only 1d values in 2d array after filter using numpy in python without loop i.e in pythonic way.

I want to filter only t2 rows and replace values in second column ( middle column ).


example:

>>> x = np.array([['t1',10,20],['t2',11,22],['t2',12,23], ['t3',21,32]])

>>> x
array([['t1', '10', '20'],
['t2', '11', '22'],
['t2', '12', '23'],
['t3', '21', '32']],
dtype='|S2')

replace_value_for_t2_col1 = [100,101]

so expected output is
----------------------

array([['t1', '10', '20'],
['t2', '100', '22'],
['t2', '101', '23'],
['t3', '21', '32']],
dtype='|S2')

What i tried was,
-----------------

Filter rows for t2

>>> x[x[:,0]=='t2']

array([['t2', '11', '22'],
['t2', '12', '23']],
dtype='|S2')

>>> x[x[:,0]=='t2'][:,1] = np.array([101,102])

Seems right, but not replacing. i guess it make a copy when we slice using [:,1], so its not changing in same array.

Please suggest me any brilliant ,simple and pythonic ideas, techniques.
Oct 29 '14 #1
0 1276

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: muttu2244 | last post by:
hi everybody i want to write a set of values to a file from python. For ex:: the fields name will "comp name", "ip addr", "mac addr" etc. And below all these fields i ll have the values for...
5
by: Krish | last post by:
Hello People I hope I am On Topic. Anyways, here is my problem. Any insights would be really appreciated. I have wrapped a C IO module using SWIG -> Python Module. Suppose the name of the...
0
by: Lasdjfk | last post by:
Anyone knows about an audio filter module for Python? Snack (http://www.speech.kth.se/snack/ ) seems to be able to do something things. However what I'm mostly interested in is to run audio...
4
by: Michael R | last post by:
I'm using this code to filter a form: Me.Form.Filter = "Remarks Is Null" Me.Form.FilterOn = True What code can I use to filter without ruining the previous, already applied filter? Also,...
1
by: Michael O'Brien | last post by:
Hola~ I have a large array of points (over a million). I would like to multiply each point in the array by a 4x4 matrix. I keep thinking there should be an easy way to do this using numpy, but I...
3
by: quiz123 | last post by:
Hi folks, I have a problem. my function call is void Rotate_n(int array, int arraySize,int n); //precondition: arraysize>=1 && n>=0 && n<=arraySize //post condition: Values in the arrary are...
6
by: Peter Wuertz | last post by:
Hi, I'm writing a C module for python, that accesses a special usb camera. This module is supposed to provide python with data (alot of data). Then SciPy is used to fit the data. My question...
5
by: shashi59 | last post by:
Now i need information about interface c and python.Now i call c function from python but i dont know how to return a array from c to python
15
by: Briansmi1116 | last post by:
I created two buttons, that filter my form, They filter in different Fields, and if one is filtered, and the other is not there is a certain amount of record, if they are both pushed, then there is...
0
by: satyasri2test | last post by:
Hi, Can some one provide me the complete example for using FILTER USING option in CREATE FUNCTION (External Scalar) for DB2 LUW 9.5. I have verified the sample given in the SQL Reference Volume2,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.