logo
down
shadow

zero values to nan values in an array of Python


zero values to nan values in an array of Python

By : user2951711
Date : November 18 2020, 03:49 PM
To fix this issue It's not that all the values become nan, it's that (1) you're only looking at the parts that do, and (2) min and max don't work well with nans.
For example, if we make an array resembling yours:
code :
>>> myarray = np.zeros((64, 52))
>>> myarray[3:-3,3:-3] = np.random.uniform(0, 5000, (64-6,52-6))
>>> myarray
array([[ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
       ..., 
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.]])
>>> myarray[myarray==0] = np.nan
>>> myarray
array([[ nan,  nan,  nan, ...,  nan,  nan,  nan],
       [ nan,  nan,  nan, ...,  nan,  nan,  nan],
       [ nan,  nan,  nan, ...,  nan,  nan,  nan],
       ..., 
       [ nan,  nan,  nan, ...,  nan,  nan,  nan],
       [ nan,  nan,  nan, ...,  nan,  nan,  nan],
       [ nan,  nan,  nan, ...,  nan,  nan,  nan]])
>>> myarray[2:5, 2:5]
array([[           nan,            nan,            nan],
       [           nan,  1500.05326562,  4583.70521213],
       [           nan,  4896.62420284,   892.83210033]])
>>> myarray.min()
nan
>>> myarray.max()
nan
>>> np.nanmin(myarray)
0.60474162939361253
>>> np.nanmax(myarray)
4996.8967777356092


Share : facebook icon twitter icon
Adding Values to an Array and getting distinct values using Python

Adding Values to an Array and getting distinct values using Python


By : visionviper
Date : March 29 2020, 07:55 AM
I wish this help you I have python code below that will loop through a table and print out values within a particular column. What is not shown is the form in which the user selects a Feature Layer. Once the Feature Layer is selected a second Dropdown is populated with all the Column Headings for that Feature and the user chooses which Column they want to focus on. Now within the python script, I simply print out each value within that column. But I want to store each value in a List or Array and get Distinct values. How can I do this in Python? , You can store distinct values in a set:
code :
>>> a = [ 1, 2, 3, 1, 5, 3, 2, 1, 5, 4 ]
>>> b = set( a )
>>> b
{1, 2, 3, 4, 5}
>>> b.add( 5 )
>>> b
{1, 2, 3, 4, 5}
>>> b.add( 6 )
>>> b
{1, 2, 3, 4, 5, 6}
for row in gp.searchcursor( fc ):
    ##grab field values
    fcValue = fields.getvalue(Atts)
    gp.AddMessage(fcValue)
How to compare values within an array in Python - find out whether 2 values are the same

How to compare values within an array in Python - find out whether 2 values are the same


By : user3327038
Date : March 29 2020, 07:55 AM
To fix this issue If you mean you have a list and you want to know if there are any duplicate values, then make a set from the list and see if it's shorter than the list:
code :
if len(set(my_list)) < len(my_list):
    print "There's a dupe!"
Convert python list with None values to numpy array with nan values

Convert python list with None values to numpy array with nan values


By : Jesus Hector Fragoso
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I am trying to convert a list that contains numeric values and None values to numpy.array, such that None is replaces with numpy.nan. , You simply have to explicitly declare the data type:
code :
>>> my_list = [3, 5, 6, None, 6, None]
>>> np.array(my_list, dtype=np.float)
array([  3.,   5.,   6.,  nan,   6.,  nan])
Get randomly the 3 minimum values of an repeated-values array in Python

Get randomly the 3 minimum values of an repeated-values array in Python


By : 王宏雷
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I've an array my_array and I want, due to specific reasons ignore the values -5 and -10 of it (yes, in the example below there's not a -10 but in other arrays I've to manage yes), and get the index of the three minimum values of the array, and append them to a new list titled lista_indices_candidatos. , How about this one:
code :
import random

def eachIndexSorted(a):  # ... without -5 and -10
  for value in sorted(set(a) - { -5, -10 }):
    indexes = [ i for i in range(len(a)) if a[i] == value ]
    random.shuffle(indexes)
    for i in indexes:
      yield i

def firstN(iterator, n):
  for i in range(n):
    yield iterator.next()

print list(firstN(eachIndexSorted(my_array), 3))
Python: Scale each row of 2d array to values that sum to 1. Each row contains some negative values

Python: Scale each row of 2d array to values that sum to 1. Each row contains some negative values


By : reddy
Date : March 29 2020, 07:55 AM
will help you First using min-max normalization to transform original data, this could be one approach:
code :
myArray = [[-1.58, -1.09, -0.41, 0.22, -0.95], 
[-1.16, -1.27, -1.89, -1.01, 1.11], 
[-0.73, -0.81, -0.47, -0.46, -0.04], 
[-1.46, -0.82, 0.40, -0.22, -1.82], 
[-1.12 , -0.97, -0.89, -0.18, 0.06]]

#Transform data
normalizedArray = []

for row in range(0, len(myArray)):
    list = []
    Min =  min(myArray[row])
    Max = max(myArray[row])

    for element in myArray[row]:
        list.append(  float(element-Min)/float(Max- Min) )

    normalizedArray.append(list)

#Normalize to 1
newArray = []

for row in range(0, len(normalizedArray)):
    list = [x / sum(normalizedArray[row]) for x in normalizedArray[row]]
    newArray.append(list)
Related Posts Related Posts :
  • ModuleNotFoundError: No module named 'users'
  • Interpolating with multiple y-values
  • Import warning PACKAGE.egg is added to sys.path
  • Is there a key for the default namespace when creating dictionary for use with xml.etree.ElementTree.findall() in Python
  • Using fill_between() with a Pandas Data Series
  • How to build a lookup table for tri-linear interpolation in NumPy?
  • Matrix vector multiplication along array axes
  • Can a cookiejar object be pickled?
  • __init__.py in project folder breaks nose tests
  • Comparing times with sub-second accuracy
  • advanced search using HayStack + Solr in Django?
  • Base test case class for python unittest
  • The PyData Ecosystem
  • Finding unique entries with oldest time stamp
  • Custom filesize format with Python Humanize?
  • Use `tf.image.resize_image_with_crop_or_pad` to resize numpy array
  • Sum number of occurences of string per row
  • Calculating 'Diagonal Distance' in 3 dimensions for A* path-finding heuristic
  • porting PyGST app to GStreamer1.0 + PyGI
  • Connection refused in Tornado test
  • How much time does take train SVM classifier?
  • Turning a string into list of positive and negative numbers
  • Python lists get specific length of elements from index
  • python.exe version 3.3.2 64 & 32 crash while creating .exe file on win 7 64 & 32 with cx_Freeze
  • Efficient nearest neighbour search for sparse matrices
  • django filter_horizontal can't display
  • How to install FLANN and pyflann on Windows
  • How can I plot the same figure standalone and in a subplot in Matplotlib?
  • read-only cells in ipython notebook
  • filling text file with dates
  • error:AttributeError: 'super' object has no attribute 'db_type' when run "python manage.py syncdb" in django
  • python imblearn make_pipeline TypeError: Last step of Pipeline should implement fit
  • Write to csv: columns are shifted when item in row is empty (Python)
  • DuckDuckGo search returns 'List Index out of range'
  • Python function which can transverse a nested list and print out each element
  • Python installing xlwt module error
  • Python mayavi: Adding points to a 3d scatter plot
  • Making a basic web scraper in Python with only built in libraries - Python
  • How to calculate the angle of the sun above the horizon using pyEphem
  • Fix newlines when writing UTF-8 to Text file in python
  • How to convert backward slash command in python to run on Linux
  • PyCharm Code Inspection doesn't include PEP 8
  • How can I use Python namedtuples to insert rows into mySQL database
  • Increase / Decrease Mac Address in Python from String
  • Scrollable QLabel image in PyQt5
  • (Python 2.7) Access variable from class with accessor/mutator
  • Why does "from [Module] import [Something]" takes more time than "import [Module"
  • jira python oauth: how to get the parameters for authentication?
  • Python - How to specify a relative path by jumping a subdirectory?
  • Extract scientific number from string
  • Scrapy: Python cannot find the spider
  • get the values in a given radius from numpy array
  • Is it possible to duplicate a pipe in Python, so that it has one write end but two read ends?
  • Why does wget use Firefox cookies to login on an authenticated webpage?
  • python import behaviour: different objects from same file?
  • Create YoY Graph with Matplotlib
  • Safe use of eval() or alternatives - python
  • Unix change desktop background seamlessly
  • Profiling Python code that uses multiprocessing?
  • How to query a database after render_template
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org