2

I am trying to do time series data analysis on all the fracking wells in pennsylvania, and naturally a lot of these are dry wells with 0 production. I want to create the histogram of each array inside the list without zero in it, therefore the total length of each array will shrink a little bit

P = [data3P, data4P, data5P, data6P, data7P, data8P, data9P, data10P]
for i in P 
N = []
for i in data3P:
if i >0:
    N.append(i)
N

I think I should do it in a for loop, but just not sure how to do that for all the arrays in the list. Shall I use a double for loop?

5
  • 3
    Which programming language? Commented Dec 14, 2015 at 23:40
  • It looks Pythonic, so maybe P = [data3P, data4P, ...] then P = [i for i in P if i > 0] Commented Dec 14, 2015 at 23:42
  • Have you got any non-working code to share? What are those data objects (numbers, arrays...)? If this is Python and they are arrays, maybe try filter(None, P). Commented Dec 14, 2015 at 23:43
  • Sorry, my bad. It's python. Commented Dec 14, 2015 at 23:46
  • The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() This is the error message from TessellatingHeckler, must be something wrong with what I did Commented Dec 14, 2015 at 23:51

2 Answers 2

0

If you are dealing with large amounts of data, numpy is your friend. You can create a masked array (where the zeros are masked), and apply the regular histogram function, see this answer for an example.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks. I got "hist is not defined", which library shall I import to make it work.
@BowenLiu You need to use pyplot.hist
@BowenLiu, you need to import numpy as np. See: docs.scipy.org/doc/numpy-1.10.0/reference/maskedarray.html. pyplot.hist is a reference to matplotlib, not the tool I was talking about.
0

I'm not 100% sure if this is what you need, but if you want to gather all the NumPy arrays datanP but without any zeros they might contain, you can do this:

[a[a!=0] for a in P]

It would help if you showed what one of those input arrays looks like, and what you'd like to get out of the processing you're trying to do.

2 Comments

That's an inefficient way to work with numpy arrays, plus it returns a list, not a numpy array.
It's not if he has a list of arrays. I can't tell what the input actually is.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.