replace the solution of problem 66 and set the difficulty
This commit is contained in:
@@ -674,20 +674,10 @@ I = [1,3,9,3,4,1]
|
||||
F = np.bincount(I,X)
|
||||
print(F)
|
||||
```
|
||||
#### 66. Considering a (w,h,3) image of (dtype=ubyte), compute the number of unique colors (★★★)
|
||||
#### 66. Considering a (w,h,3) image of (dtype=ubyte), compute the number of unique colors (★★☆)
|
||||
|
||||
|
||||
```python
|
||||
# Author: Nadav Horesh
|
||||
|
||||
w,h = 16,16
|
||||
I = np.random.randint(0,2,(h,w,3)).astype(np.ubyte)
|
||||
# The parenthesis around 256*256 ensure the dtpye promoted to uint32 properly.Otherwise the first term will overflow.
|
||||
F = I[...,0]*(256*256) + I[...,1]*256 +I[...,2]
|
||||
n = len(np.unique(F))
|
||||
print(np.unique(I))
|
||||
|
||||
# Another solution
|
||||
# Author: Fisher Wang
|
||||
|
||||
w, h = 16, 16
|
||||
|
||||
Reference in New Issue
Block a user