How do I get the count of a Swift enum?

As of Swift 4.2 (Xcode 10) you can declare conformance to the CaseIterable protocol, this works for all enumerations without associated values: enum Stuff: CaseIterable { case first case second case third case forth } The number of cases is now simply obtained with print(Stuff.allCases.count) // 4 For more information, see SE-0194 Derived Collection of … Read more

How to count the number of true elements in a NumPy bool array

You have multiple options. Two options are the following. boolarr.sum() numpy.count_nonzero(boolarr) Here’s an example: >>> import numpy as np >>> boolarr = np.array([[0, 0, 1], [1, 0, 1], [1, 0, 1]], dtype=np.bool) >>> boolarr array([[False, False, True], [ True, False, True], [ True, False, True]], dtype=bool) >>> boolarr.sum() 5 Of course, that is a bool-specific … Read more

COUNT(*) vs. COUNT(1) vs. COUNT(pk): which is better? [duplicate]

Bottom Line Use either COUNT(field) or COUNT(*), and stick with it consistently, and if your database allows COUNT(tableHere) or COUNT(tableHere.*), use that. In short, don’t use COUNT(1) for anything. It’s a one-trick pony, which rarely does what you want, and in those rare cases is equivalent to count(*) Use count(*) for counting Use * for … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)